%PDF- %PDF-
Direktori : /var/www/html/diaspora/api_internal/app/Models/ |
Current File : /var/www/html/diaspora/api_internal/app/Models/Category.php |
<?php namespace App\Models; use Dimsav\Translatable\Translatable; /** * @property integer id * @property string slug * @property string name * @property boolean is_archived * @property mixed created_at * @property mixed updated_at */ class Category extends BaseModel { use Translatable; public $timestamps = false; public $translatedAttributes = [ 'name', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'slug', 'name', ]; protected $guarded = [ 'author_id', ]; protected $casts = [ 'id' => 'integer', 'slug' => 'string', 'name' => 'string', 'is_archived' => 'boolean', ]; public function posts() { return $this->belongsToMany(Post::class, 'category_post'); } public function canUse() { return !$this->is_archived && $this->translations() ->count() === 2; } public function archive() { $this->is_archived = true; $this->save(); return $this; } public function unArchive() { $this->is_archived = false; $this->save(); return $this; } public function hasConfiguration($uuid) { /** @var Device $device */ $device = Device::query() ->where("uuid", $uuid) ->first(); if (!$device) { return false; } return $device->configurations() ->where('category_id', $this->id) ->exists(); } }