Skip to content

anaseqal/nova-sidebar-icons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nova Sidebar Icons

Set icons for resources in sidebar.

screenshot

Installation

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

composer require anaseqal/nova-sidebar-icons

Publish navigation view file:

php artisan vendor:publish --provider="Anaseqal\NovaSidebarIcons\ToolServiceProvider" --force

Register the tool in NovaServiceProvider:

use Anaseqal\NovaSidebarIcons\NovaSidebarIcons;
...

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

Usage

Set the icon in your Nova resource, for example:

/**
 * The icon of the resource.
 *
 * @return string
 */
public static function icon() 
{
    // Assuming you have a blade file containing an image
    // in resources/views/vendor/nova/svg/icon-user.blade.php
    return view('nova::svg.icon-user')->render();
}

This is the recommended approach. In the example above we have used a blade file containing an svg, but if you'd want to it's is possible return the entire svg string

Examples of other approaches

// By using an image tag
public static function icon() 
{
    return '<img src="/path/to/image.svg" />';
}

// Or simply return it as a string
public static function icon() 
{
    return '<svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                <path fill="var(--sidebar-icon)" d="M4.06 13a8 8 0 0 0 5.18 .... e.t.c."/>
            </svg>';
}
    

Backwards compatibility

Please note that this package used to use a static $icon property on the resource. This has been replaced with the static icon method. The icon property is still supported to preserve backwards compatibility.

License

The MIT License (MIT). Please see License File for more information.