LaravelPackages.net
Acme Inc.
Toggle sidebar
kineticamobile/atrochar

Menu Generator for Laravel Apps - Populate menus in your views using Database backed Menus with @menu Blade component

98
1
v0.1.8
About kineticamobile/atrochar

kineticamobile/atrochar is a Laravel package for menu generator for laravel apps - populate menus in your views using database backed menus with @menu blade component. It currently has 1 GitHub stars and 98 downloads on Packagist (latest version v0.1.8). Install it with composer require kineticamobile/atrochar. Discover more Laravel packages by kineticamobile or browse all Laravel packages to compare alternatives.

Last updated

Atrochar

Menu Generator for Laravel Apps - Populate menus in your views using Database backed Menus with @menu Blade component

Installation

  1. Via Composer
$ composer require kineticamobile/atrochar
  1. Add trait to your User model.

use Kineticamobile\Atrochar\Traits\MenuAbilities;

class User extends Authenticatable
{

    use MenuAbilities;
  1. Run migrations
$ php artisan migrate

Simple Usage

Create Menus and its items

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>

Add a created menu in your views with blade component

  • Using menu name
    @menu("Dasboard")
  • Using menu id
    @menu(1)
  • Using menu object
    $menu = Menu::find(1);
    [...]
    @menu($menu)

Use views instead of programatic approach

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) use default

  • @menuview($menu, 'jetstream') use jetstream

Advanced Usage

Change Prefix of Package Routes

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.

Change iframe routes

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

Restrict access to menu management

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);
    }

Style your menus using themes or overriding default values

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"])

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

Licence

MIT

Comments