e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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', 'created_at', 'updated_at', 'deleted_at'];
|
|
|
|
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();
|
|
}
|
|
}
|