wehaa / custom-links
为 Nova 侧边栏添加自定义链接。
v0.1.1
2019-09-14 02:00 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-14 13:07:41 UTC
README
此工具允许您将自定义链接作为侧边栏部分或单个顶级链接添加。
安装
您可以通过 composer 将该软件包安装到使用 Nova 的 Laravel 应用中。
composer require wehaa/custom-links
然后您必须使用 Nova 注册此工具。这通常在 NovaServiceProvider
的 tools
方法中完成。
// in app/Providers/NovaServiceProvider.php use Wehaa\CustomLinks\CustomLinks; // ... public function tools() { return [ // ... new CustomLinks(), ]; }
要发布配置文件到 config/custom-links.php
,请运行
php artisan vendor:publish --provider="Wehaa\CustomLinks\ToolServiceProvider"
要添加链接到导航部分,您需要在配置文件中的 links
部分添加条目。
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) ] ] ] ] ];
包含的配置文件将添加一些您可以用作示例的链接。
授权
如果您只想向特定用户公开链接,您可以将 canSee
方法链接到您的工具注册中。
// in app/Providers/NovaServiceProvider.php use Wehaa\CustomLinks\CustomLinks; // ... public function tools() { return [ // ... (new CustomLinks)->canSee(function ($request) { return false; }), ]; }
此外,您可以在链接数组中添加键 _can
,包括子链接。我们将使用 can()
函数来检查用户是否有查看链接的权限。
请注意,如果您不想进行任何授权检查,请不要添加 _can
键。
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 // ... ] ] ] ] ];