在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):vyuldashev/nova-permission开源软件地址(OpenSource Url):https://github.com/vyuldashev/nova-permission开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):A Laravel Nova tool for Spatie's laravel-permission libraryInstallationYou can install the package in to a Laravel app that uses Nova via composer: composer require vyuldashev/nova-permission Go through the Installation section in order to setup laravel-permission. Next up, you must register the tool with Nova. This is typically done in the // in app/Providers/NovaServiceProvider.php
// ...
public function tools()
{
return [
// ...
\Vyuldashev\NovaPermission\NovaPermissionTool::make(),
];
} Next, add middleware to // in config/nova.php
'middleware' => [
// ...
\Vyuldashev\NovaPermission\ForgetCachedPermissions::class,
], Finally, add // ...
use Laravel\Nova\Fields\MorphToMany;
public function fields(Request $request)
{
return [
// ...
MorphToMany::make('Roles', 'roles', \Vyuldashev\NovaPermission\Role::class),
MorphToMany::make('Permissions', 'permissions', \Vyuldashev\NovaPermission\Permission::class),
];
} Or if you want to attach multiple permissions at once, use // ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleBooleanGroup;
public function fields(Request $request)
{
return [
// ...
RoleBooleanGroup::make('Roles'),
PermissionBooleanGroup::make('Permissions'),
];
} If your // ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleSelect;
public function fields(Request $request)
{
return [
// ...
RoleSelect::make('Role', 'roles'),
];
} CustomizationIf you want to use custom resource classes you can define them when you register a tool: // in app/Providers/NovaServiceProvider.php
// ...
public function tools()
{
return [
// ...
\Vyuldashev\NovaPermission\NovaPermissionTool::make()
->roleResource(CustomRole::class)
->permissionResource(CustomPermission::class),
];
} If you want to show your roles and policies with a custom label, you can set // ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleSelect;
public function fields(Request $request)
{
return [
// ...
RoleBooleanGroup::make('Roles', 'roles', null, 'description'),
PermissionBooleanGroup::make('Permissions', 'permissions', null, 'description'),
RoleSelect::make('Role', 'roles', null, 'description'),
];
} Define Policies// in app/Providers/NovaServiceProvider.php
// ...
public function tools()
{
return [
// ...
\Vyuldashev\NovaPermission\NovaPermissionTool::make()
->rolePolicy(RolePolicy::class)
->permissionPolicy(PermissionPolicy::class),
];
} UsageA new menu item called "Permissions & Roles" will appear in your Nova app after installing this package. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论