moonshine/permissions

User permissions for MoonShine

2.0.0 2024-10-13 17:02 UTC

This package is auto-updated.

Last update: 2024-12-19 17:37:50 UTC


README

Requirements

  • MoonShine v3.0+

Support MoonShine versions

Installation

composer require moonshine/permissions

Run migrations

php artisan migrate

Get started

  1. Change MoonshineUser model in config/moonshine.php or in MoonShineServiceProvider
use MoonShine\Permissions\Models\MoonshineUser;

return [
    // ...
    'auth' => [
        // ...
        'providers' => [
            'moonshine' => [
                'driver' => 'eloquent',
                'model' => MoonshineUser::class,
            ],
        ],
    ],
    // ...
];

Or add trait HasMoonShinePermissions to user model

use MoonShine\Permissions\Traits\HasMoonShinePermissions;

class MoonshineUser extends Model
{
    use HasMoonShinePermissions;
}
  1. Add trait WithPermissions to MoonShineUserResource and change $model
use MoonShine\Permissions\Traits\WithPermissions;

class MoonShineUserResource extends ModelResource
{
    use WithPermissions;

    public string $model = MoonShine\Permissions\Models\MoonshineUser::class;

    // ...
}

Example of condition to display in menu

use MoonShine\Laravel\Enums\Ability;

protected function menu(): array
{
    return [
        MenuItem::make('Posts', PostResource::class)
            ->canSee(fn () => auth()->user()->isHavePermission(PostResource::class, Ability::VIEW))
        ,
    ];
}