таблицы - это роли, меню, Role_menus.
Пользователь увидит только те меню, к которым он имеет доступ. < /P>
Вот есть только те меню. Мой код: < /p>
Вот мой путь контроллера < /p>
Код: Выделить всё
$menuList = Menu::tree()->with('roleMenus')->where('per_select','=',0);
< /code>
Вот модель < /p>
class Menu extends Model
{
use HasFactory;
protected $table = "menus";
protected $fillable = ['title', 'url', 'parent_id', 'sort_order'];
public function parent()
{
return $this->hasOne('App\Models\Menu', 'id', 'parent_id')->orderBy('sort_order');
}
public function children()
{
return $this->hasMany('App\Models\Menu', 'parent_id', 'id')->orderBy('sort_order');
}
public static function tree()
{
return static::with(implode('.', array_fill(0, 100, 'children')))->where('parent_id', '=', '0')->orderBy('sort_order', 'asc')->get();
}
public function roleMenus()
{
return $this->belongsToMany(Role::class);
}
}
Подробнее здесь: https://stackoverflow.com/questions/663 ... a-eloquent