Skip to content

Latest commit

 

History

History
86 lines (64 loc) · 1.52 KB

README.md

File metadata and controls

86 lines (64 loc) · 1.52 KB

MoonShine Permission

Requirements

  • MoonShine v3.0+

Support MoonShine versions

MoonShine ChangeLog
2.0+ 1.0+
3.0+ 2.0+

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))
        ,
    ];
}