58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\BaseModel;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class NavItem extends BaseModel
|
|
{
|
|
protected $table = 'nav_items';
|
|
|
|
// ✅ legacy: timestamps + soft deletes
|
|
use SoftDeletes;
|
|
public $timestamps = true;
|
|
|
|
protected $fillable = [
|
|
'menu_parent_id',
|
|
'label',
|
|
'url',
|
|
'icon_class',
|
|
'target',
|
|
'sort_order',
|
|
'is_enabled',
|
|
];
|
|
|
|
protected $casts = [
|
|
'menu_parent_id' => 'integer',
|
|
'sort_order' => 'integer',
|
|
'is_enabled' => 'boolean',
|
|
];
|
|
|
|
/* Optional relationships */
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(self::class, 'menu_parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(self::class, 'menu_parent_id');
|
|
}
|
|
|
|
/**
|
|
* Equivalent of legacy getChildrenOf()
|
|
* NOTE: legacy code uses where('parent_id', ...) but allowedFields has menu_parent_id.
|
|
* This Laravel version uses menu_parent_id (likely correct).
|
|
*/
|
|
public static function getChildrenOf(int $parentId): array
|
|
{
|
|
return static::query()
|
|
->where('menu_parent_id', $parentId)
|
|
->where('is_enabled', 1)
|
|
->orderBy('label', 'asc')
|
|
->orderBy('id', 'asc')
|
|
->get()
|
|
->toArray();
|
|
}
|
|
} |