reconstruction of the project
This commit is contained in:
+36
-8
@@ -3,13 +3,17 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class NavItem extends BaseModel
|
||||
{
|
||||
protected $table = 'nav_items';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
// ✅ CI: timestamps + soft deletes
|
||||
use SoftDeletes;
|
||||
|
||||
public $timestamps = true;
|
||||
protected $useSoftDeletes = true;
|
||||
|
||||
protected $fillable = [
|
||||
'menu_parent_id',
|
||||
'label',
|
||||
@@ -23,11 +27,35 @@ class NavItem extends BaseModel
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
public function getChildrenOf(int $parentId): array
|
||||
protected $casts = [
|
||||
'menu_parent_id' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
'is_enabled' => 'boolean',
|
||||
];
|
||||
|
||||
/* Optional relationships */
|
||||
public function parent()
|
||||
{
|
||||
return $this->where('parent_id', $parentId)
|
||||
->where('is_enabled', 1)
|
||||
->orderBy('sort_order', 'ASC')
|
||||
->findAll();
|
||||
return $this->belongsTo(self::class, 'menu_parent_id');
|
||||
}
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(self::class, 'menu_parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of CI getChildrenOf()
|
||||
* NOTE: CI 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('sort_order', 'asc')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user