anaseqal/nova-sidebar-icons

Laravel Nova 工具。

0.0.3 2019-08-29 18:49 UTC

This package is not auto-updated.

Last update: 2024-09-20 18:59:20 UTC


README

为侧边栏中的资源设置图标。

screenshot

安装

您可以通过 composer 安装该包到使用 Nova 的 Laravel 应用中。

composer require anaseqal/nova-sidebar-icons

发布导航视图文件

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

NovaServiceProvider 中注册工具

use Anaseqal\NovaSidebarIcons\NovaSidebarIcons;
...

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

用法

在您的 Nova 资源中设置图标,例如

/**
 * 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();
}

这是推荐的方法。在上面的例子中,我们使用了一个包含 svg 的 blade 文件,但如果需要,也可以返回整个 svg 字符串

其他方法示例

// 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>';
}
    

向下兼容性

请注意,此包之前在资源中使用了静态的 $icon 属性。这已被替换为静态的 icon 方法。为了保持向下兼容性,icon 属性仍然受支持。

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件