Files
marcoandClaude Sonnet 4.6 4916edab7f
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 6s
Add show_in_nav option for categories in top menu
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 19:16:12 +02:00

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);
}
}