41 lines
980 B
PHP
41 lines
980 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dyrynda\Database\Support\CascadeSoftDeletes;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Sluggable\HasSlug;
|
|
use Spatie\Sluggable\SlugOptions;
|
|
use Veelasky\LaravelHashId\Eloquent\HashableId;
|
|
|
|
class Category extends Model
|
|
{
|
|
use CascadeSoftDeletes, HasFactory, HashableId, HasSlug, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $cascadeDeletes = ['perfumes'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'sort_order' => 'int',
|
|
];
|
|
}
|
|
|
|
public function getSlugOptions(): SlugOptions
|
|
{
|
|
return SlugOptions::create()
|
|
->generateSlugsFrom('name')
|
|
->saveSlugsTo('slug');
|
|
}
|
|
|
|
public function perfumes(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Perfume::class);
|
|
}
|
|
}
|