- MoonShine v3.0+
MoonShine | ChangeLog |
---|---|
2.0+ | 1.0+ |
3.0+ | 2.0+ |
composer require moonshine/permissions
php artisan migrate
- 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;
}
- 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;
// ...
}
use MoonShine\Laravel\Enums\Ability;
protected function menu(): array
{
return [
MenuItem::make('Posts', PostResource::class)
->canSee(fn () => auth()->user()->isHavePermission(PostResource::class, Ability::VIEW))
,
];
}