50 lines
1.0 KiB
PHP
50 lines
1.0 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class Category extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'slug',
|
|
|
|
'description'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot the model.
|
|
|
|
*/
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::creating(function ($category) {
|
|
|
|
$category->slug = Str::slug($category->name);
|
|
|
|
});
|
|
|
|
|
|
|
|
static::updating(function ($category) {
|
|
|
|
$category->slug = Str::slug($category->name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the subcategories for the category.
|
|
|
|
*/
|
|
|
|
public function subcategories()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Subcategory::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cafes for the category.
|
|
|
|
*/
|
|
|
|
public function cafes()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Cafe::class);
|
|
|
|
}
|
|
|
|
}
|