belongsTo(User::class, 'creator_id', 'id'); } public function children(){ return $this->hasMany( Category::class, 'parent_id' ); } public function parent() { return $this->belongsTo(Category::class); } public function products() { return $this->morphedByMany(Product::class, 'categorizable'); } public function getCategoryTypeAttribute($value) { switch ($value) { case 0: $category_type = 'محصولات'; break; case 1: $category_type = 'اخبار'; break; case 2: $category_type = 'مطالب'; break; default: $category_type = ''; } return $category_type; } public function sluggable() { return [ 'slug' => [ 'source' => 'title' ] ]; } }