43 lines
872 B
PHP
43 lines
872 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class Category extends Model
|
|
{
|
|
use HasFactory,Sluggable;
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
|
|
|
/**
|
|
* Return the sluggable configuration array for this model.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function sluggable(): array
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'name',
|
|
'onUpdate' => true
|
|
]
|
|
];
|
|
}
|
|
|
|
public function parent(){
|
|
return $this->belongsTo(Category::class, 'category_id');
|
|
}
|
|
|
|
public function children(){
|
|
return $this->hasMany(Category::class);
|
|
}
|
|
|
|
public function products()
|
|
{
|
|
return $this->hasMany(Product::class);
|
|
}
|
|
}
|