Menu Generator for Laravel Apps - Populate menus in your views using Database backed Menus with @menu Blade component
- Via Composer
$ composer require kineticamobile/atrochar
- Add trait to your User model.
use Kineticamobile\Atrochar\Traits\MenuAbilities;
class User extends Authenticatable
{
use MenuAbilities;
- Run migrations
$ php artisan migrate
You can access the Menu Management in your app "APP_URL/atrochar/menus"
or add link wherever you want
<a href="{{ route('atrochar.menus.index') }}"> {{ __('Menus') }} </a>
- Using menu name
@menu("Dasboard")
- Using menu id
@menu(1)
- Using menu object
$menu = Menu::find(1);
[...]
@menu($menu)
You can publish the views of the components
$ php artisan vendor:publish --tag=atrochar.views
You have two views in resources/views/vendors/atrochar
, default.blade.php
nad jetstream.blade.php
To use these views see examples below
-
@menuview($menu)
usedefault
-
@menuview($menu, 'jetstream')
usejetstream
Publish configuration
$ php artisan vendor:publish --tag=atrochar.config
Modify conf/atrochar.php
field prefix
. It allows empty string, if null atrochar
would be used.
Usually iframe links are in route atrochar/i/24
You can change i
for whatever you want in conf/atrochar.php
field iframe
after publish the configuration file
$ php artisan vendor:publish --tag=atrochar.config
By default all users can manage menus.
You need to add the method canManageMenus()
to your user model:
/**
* @return bool
*/
public function canManageMenus()
{
// For example
return $this->hasRole('Admin');
}
By default all items can be viewed. But you can add permission in your links, if not empty this ability is checked against the User method canViewMenuItem($ability)
You need to add the method canViewMenuItem($ability)
to your user model to extend this behavior:
/**
* @return bool
*/
public function canViewMenuItem($ability)
{
// For example
return $this->getAllPermissions()->pluck('name')->contains($ability);
}
Using themes. Publish the config file in your app. In config/atrochar.php you can modify default values or add new themes
$ php artisan vendor:publish --tag=atrochar.config
return [
"defaultTheme" => [
"linkTag" => "a",
"class" => "",
"activeClass" => "",
"listStartTag" => "<ul>",
"listEndTag" => "</ul>",
"itemStartTag" => "<li>",
"itemEndTag" => "</li>",
],
"themes" => [
"jetstream" => [
"linkTag" => "a",
"class" => "inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium leading-5 text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out",
"activeClass" => "inline-flex items-center px-1 pt-1 border-b-2 border-indigo-400 text-sm font-medium leading-5 text-gray-900 focus:outline-none focus:border-indigo-700 transition duration-150 ease-in-out",
"listStartTag" => "",
"listEndTag" => "",
"itemStartTag" => "",
"itemEndTag" => "",
]
]
];
Once you've created a theme you can pass a string as a second argument in the @menu component the name of the theme
@menu("Dasboard", "jetstream")
If you pass an array as second argument the values override the defaultTheme values
@menu($menu, ["class" => "bg-gray-500 font-mono"])
If you discover any security related issues, please email author email instead of using the issue tracker.
MIT