A laravel UI wrapper for spatie/laravel-permission with Bootstrap 4!
- 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.
- 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.
- 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/