26 lines
599 B
PHP
26 lines
599 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
class Category extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = ['name', 'keywords'];
|
||
|
|
|
||
|
|
protected static function booted()
|
||
|
|
{
|
||
|
|
static::creating(function ($category) {
|
||
|
|
// Otomatis membuat slug dari name sebelum data disimpan
|
||
|
|
if (empty($category->slug)) {
|
||
|
|
$category->slug = Str::slug($category->name);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
public function medicines(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Medicine::class);
|
||
|
|
}
|
||
|
|
}
|