maestriam/hiker

Create menus and breadcrumbs for you projects.

v0.0.10 2020-08-03 01:24 UTC

This package is auto-updated.

Last update: 2024-04-29 04:27:34 UTC


README

hiker.png

Create breadcrumbs and menus for your Laravel projects.

🗻 Maestriam/Hiker

Maestriam/Hiker is a package for creating menus and breadcrumbs using Laravel Routes.
Under construction!

Requirements

  • Laravel 6.*^

Installation

Install via composer

composer require maestriam/hiker

Getting Started

Preparing routes

Let's start creating some routes normally using Laravel Routes.
You must declaring as and uses params.

    Route::get('/test/edit/{id}', [
        'as'    => 'test.edit',
        'uses'  => 'TestController@edit'
    ]);

Optional attributes

Optionally, you can add others params into yout route

    Route::get('/test', [
        'as'    => 'test.index',
        'uses'  => 'TestController@index'
        'icon'  => 'flag',
        'label' => 'My Route Index',
        'desc'  => 'A common index route' 
    ]);

Menu

Create a new menu

    $menu = Hiker::menu('test-menu');

Now, let's add some routes in it

    $menu = Hiker::menu('test-menu')
                 ->push('test.index')
                 ->push('test.view')
                 ->push('test.edit);

Into your php class, we can dump our menu this way

    $menu = Hiker::menu('test-menu');

    foreach($menu->collection as $route) {
        dump($route->url);
    }

The above example will output (if is localhost with php artisan serve):

    http://localhost:8000/test
    http://localhost:8000/view/1
    http://localhost:8000/edit/1

We can render into blade file

    @foreach($menu->collection as $route)
        {{ $route->url }}
    @endforeach

Breadcrumb

Creating breadcrumb

Create a new middleware and put into your function.

    Hiker::breadcrumb('my-breadcrumb')

Creating namesake breadcrumb

You can create namesake breadcrumbs. Just name it breadcrumb with same name that you route.
Automatically, the last item of breadcrumb will be the route that your name given

    Hiker::breadcrumb('my-route')

Adding routes

To add routes into breadcrumb, just call function push passing route name as parameter;
You can pass others parameters for construction of route

    Hiker::breadcrumb('my-breadcrumb')
         ->push('test.index')
         ->push('test.index', ['id' => 1]);

Get routes

To get added routes, just access collection attribute:

    $breadcrumb = Hiker::breadcrumb('my-breadcrumb');

    $breadcrumb->collection;




Created by Giuliano Sampaio with ❤️ and 🍺!