| Current Path : /var/www/html/LLCF-APP/app/Models/ |
| Current File : /var/www/html/LLCF-APP/app/Models/Item.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Item extends Model
{
use HasFactory;
protected $table = 'items';
protected $fillable = [
'name',
'slug',
];
/**
* Automatically generate a slug from the name if not provided.
*/
protected static function booted(): void
{
static::creating(function ($item) {
if (empty($item->slug)) {
$item->slug = Str::slug($item->name);
}
});
static::updating(function ($item) {
if (empty($item->slug)) {
$item->slug = Str::slug($item->name);
}
});
}
public function expenses()
{
return $this->hasMany(Expense::class, 'item_id');
}
}