add projet
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class RoleNavItem extends BaseModel
|
||||
{
|
||||
protected $table = 'role_nav_items';
|
||||
protected $primaryKey = 'id';
|
||||
public $timestamps = true;
|
||||
|
||||
// ✅ columns that actually exist now
|
||||
protected $fillable = [
|
||||
'role_id',
|
||||
'nav_item_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Accepts role names (strings from session), resolves to role IDs, then returns allowed nav_item_ids.
|
||||
*/
|
||||
public function getNavItemIdsForRoles(array $roleNames): array
|
||||
{
|
||||
$roleNames = array_values(array_filter(array_map('strval', $roleNames)));
|
||||
if (empty($roleNames)) return [];
|
||||
|
||||
$role = new Role();
|
||||
$roleIds = $role->getIdsByNames($roleNames);
|
||||
if (empty($roleIds)) return [];
|
||||
|
||||
$rows = $this->select('nav_item_id')
|
||||
->whereIn('role_id', $roleIds)
|
||||
->findAll();
|
||||
|
||||
return array_values(array_unique(array_column($rows, 'nav_item_id')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user