moonshine / permissions
User permissions for MoonShine
Installs: 4 109
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.1|^8.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- brianium/paratest: ^6.8
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0
- phpstan/phpstan: ^1.4.7
- phpunit/phpunit: ^9.5.8
- rector/rector: ^1.0
Conflicts
- moonshine/moonshine: <3.0
README
Requirements
- MoonShine v3.0+
Support MoonShine versions
Installation
composer require moonshine/permissions
Run migrations
php artisan migrate
Get started
- 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; // ... }
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)) , ]; }