/
Category.php
54 lines (45 loc) · 1.29 KB
/
Category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Module\Category\Models;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Module\Category\Casts\NameCategory;
use Module\Category\Database\Factories\CategoryFactory;
use Module\Lang\Traits\LangService;
use Module\Media\Models\Media;
use Module\Post\Models\Post;
use Module\Share\Traits\UseUuid;
class Category extends Model
{
use HasFactory, SoftDeletes, LangService, UseUuid;
protected $guarded = [];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'name' => NameCategory::class,
];
public $translatable = ['name'];
/**
* Create a new factories instance for the model.
*
* @return Factory
*/
protected static function newFactory(): Factory
{
return CategoryFactory::new();
}
/* Relations */
public function images(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(Media::class, 'mediaable');
}
/* Relations */
public function posts(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Post::class);
}
}