I got the problem when using bican/roles
Role module in my Laravel project.
There is an error when I check permission.
So I decided to move zizaco/entrust
and tested all features working normal.
$ composer require zizaco/entrust:5.2.x-dev
config/app.php
Add bellow line to providers
array in config/app.php
.
ZizacoEntrustEntrustServiceProvider::class,
Add bellow line to aliases
array in config/app.php
.
'Entrust' => ZizacoEntrustEntrustFacade::class,
app/Http/Kernal.php
Add bellow lines to routeMiddleware
array in app/Http/Kernal.php
.
'role' => ZizacoEntrustMiddlewareEntrustRole::class,
'permission' => ZizacoEntrustMiddlewareEntrustPermission::class,
'ability' => ZizacoEntrustMiddlewareEntrustAbility::class,
entrust.php
file$ php artisan vendor:publish
$ php artisan entrust:migration
It will generate the
migration.
Execute migration
$ php artisan migrate
After create
, you have to write your users table in this file. Open
file and write name of users table to 28 line
.
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
Set CACHE_DRIVER=array
in .env
file.
In Laravel 5.2, error is occured when delete role. Because Entrust get User class using Config::get('auth.model')
.
EntrustRoleTrait.php file
/**
* Many-to-Many relations with the user model.
*
* @return IlluminateDatabaseEloquentRelationsBelongsToMany
*/
public function users()
{
return $this->belongsToMany(Config::get('auth.model'), Config::get('entrust.role_user_table'),Config::get('entrust.role_foreign_key'),Config::get('entrust.user_foreign_key'));
// return $this->belongsToMany(Config::get('auth.model'), Config::get('entrust.role_user_table'));
}
So We have to return right user model by that position. There are two solutions for this.
We can change Config::get('auth.model')
to Config::get('auth.providers.users.model')
. Laravel 5.2 already have users model information in that position.
auth.model
value to config/auth.php fileWe can also add new value to config/auth.php file to allow Entrust get rights value.
return [
...
/**
* Add this configuration for Entrust
*/
'model' => AppUser::class,
];