dainsys / locky
A laravel UI wrapper for spatie/laravel-permission with Bootstrap 4!
2.5.1
2021-06-27 03:52 UTC
Requires
- php: ^7.2
- dainsys/components: ^1.0
- laravel/framework: ^6.0|^7.0|^8.0
- livewire/livewire: ^2.4
- spatie/laravel-permission: ^3.0
Requires (Dev)
- laravel/legacy-factories: 1.x-dev
- laravel/ui: ^3.0
- orchestra/testbench: ^6.0
README
A laravel UI wrapper for spatie/laravel-permission with Bootstrap 4!
Installation
- Install with
composer
by runining the commandcomposer require dainsys/locky
- Add the
Dainsys\Locky\WithLockyAcl;
to yourUser
model(s);
use Illuminate\Foundation\Auth\User as Authenticatable; use Dainsys\Locky\WithLockyAcl; class User extends Authenticatable { use WithLockyAcl; }
- Add the following item to the
protected $casts
array:protected $casts = [ 'inactivated_at' => 'date' ];
- Set you
LOCKY_SUPER_USER_EMAIL=super.user@email-example.com
in the .env file. - This package relies on you having an auth system. We strongly suggest using
laravel/jetstream
,laravel/freeze
or the legacylaravel/ui
- Views:
- The package ships with it's own views, therefore you MUST publish the package public assets by running
php artisan vendor:publish --tag=locky-public
. However, this is not necessary if you are planning to use your views. In this case you can runphp artisan vendor:publish --tag=locky-views
and make them extends your own layout view.
- Migrations:
- By default the packages migrations will run if you execute the
php artisan migrate
command. However, you can set thewith_migrations
option to false and handle the migrations yourselve. To do this, first run thephp artisan vendor:publish --tag=locky-config
command. - Add the following liks to the auth portion of your
layouts.app
links:
@include('locky::_nav-links')
- You could also publish the package migrations by running
php artisan vendor:publish --tag=locky-migrations
and tweak them to suit your needs.
Usage
- After installing this package, you can limit user access by creating Laravel Policies with
php artisan make:policy
command and add the checksreturn $user->hasAnyRole(["role1", "role2"])
orreturn $user->hasAnyPermission(["permission1", "permission2"])
and by updating the Controller's constructor method:
use App\YourModel; class MyController extends Controller { public function __construct() { $this->authorizeResource(YourModel::class, 'model'); } }
- Please read Larave Authorization's documentations at https://laravel.com/docs/7.x/authorization
- This package add the concept of actives or inactive users by adding query scopes. Just use the scope
actives()
orinactives()
to filter as desired. - You can activate an user by calling the
activate()
method on a Eloquent User record; useinactivate()
to inactivate an user.
Dependencies
- Dainsys Components: https://packagist.org/packages/dainsys/components
- Laravel Ui: https://laravel.com/docs/7.x/authorization
- Spatie Permission: https://docs.spatie.be/laravel-permission/v3/introduction/