wehaa/custom-links

Adds custom links to Nova sidebar.

Installs: 362 442

Dependents: 0

Suggesters: 0

Security: 0

Stars: 12

Watchers: 6

Forks: 6

Open Issues: 3

Language:HTML

v0.1.1 2019-09-14 02:00 UTC

This package is auto-updated.

Last update: 2024-04-14 12:17:17 UTC


README

This tool allows you to add a custom links as a section in your sidebar or a single top level link.

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require wehaa/custom-links

Then you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.

// in app/Providers/NovaServiceProvider.php

use Wehaa\CustomLinks\CustomLinks;

// ...

public function tools()
{
    return [
        // ...
        new CustomLinks(),
    ];
}

To publish the config file to config/custom-links.php run:

php artisan vendor:publish --provider="Wehaa\CustomLinks\ToolServiceProvider"

To add links to the navigation section you need to add entries to the links section in the config file.

return [
    'links' => [
        '{TEXT}' => [                           // Top level section title text
            '_can'    => '{PERMISSION}'         // The name of the permission
            '_icon'   => '{ICON}',              // SVG icon code (optional)
            '_url'    => '{URL}',               // URL (optional if _links is present)
            '_target' => '{TARGET}',            // Link target (optional) 
            '_links'  => [                      // Section extra links (optional if _url is present
                '{TEXT}' => [                   // Sub section text
                    '_can'    => '{PERMISSION}' // The name of the permission
                    '_url'    => '{URL}',       // URL
                    '_target' => '{TARGET}',    // Link target (optional)
                ]
            ]
        ]
    ]
];

The included config file will add some links you can use as an example.

Authorization

If you would like to only expose your links to certain users, you may chain the canSee method onto your tool's registration.

// in app/Providers/NovaServiceProvider.php

use Wehaa\CustomLinks\CustomLinks;

// ...

public function tools()
{
    return [
        // ...
        (new CustomLinks)->canSee(function ($request) {
            return false;
        }),
    ];
}

In addition, you can add the key _can in the links array, including the child links as well. We will use the can() function to check if the user has the permission to see the links or not.

Please note that if you don't want any authorization checks, do not add the _can key.

return [
    'links' => [
        '{TEXT}' => [                           // Top level section title text
            '_can'    => '{PERMISSION}'         // Checks if the link and sublinks can be shown
            // ...
            '_links'  => [                      // Section extra links (optional if _url is present
                '{TEXT}' => [                   // Sub section text
                    '_can'    => '{PERMISSION}' // Checks if the link can be shown
                    // ...
                ]
            ]
        ]
    ]
];