Files
twotalesanimation 6de01c13c5 New Initial Commit
2025-12-09 12:04:54 +02:00

39 lines
796 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Category extends Model
{
protected $fillable = [
'name',
'slug',
'description',
'image'
];
protected static function boot()
{
parent::boot();
static::creating(function ($category) {
if (empty($category->slug)) {
$category->slug = Str::slug($category->name);
}
});
static::updating(function ($category) {
if ($category->isDirty('name') && !$category->isDirty('slug')) {
$category->slug = Str::slug($category->name);
}
});
}
public function products()
{
return $this->hasMany(Product::class);
}
}