Deploy to Production (witstore.wende.it) / deploy (push) Successful in 6s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
753 B
PHP
30 lines
753 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Category extends Model
|
|
{
|
|
protected $fillable = ['parent_id','name','slug','description','image','sort_order','active','show_in_nav'];
|
|
|
|
protected $casts = ['active' => 'boolean', 'show_in_nav' => 'boolean'];
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(Category::class, 'parent_id')->orderBy('sort_order');
|
|
}
|
|
|
|
public function products(): HasMany
|
|
{
|
|
return $this->hasMany(Product::class);
|
|
}
|
|
}
|