I'm new in Laravel. I'm trying to use in Laravel 5 Zizaco/entrust (from laravel-5 branch). All working ok - attach rules, detach rules... but when I try check permissions I have problems.
First I try in routes.php, but in this place Entrust don't know who am I, hasRole
and routeNeedsRole
not working in routes.php.
In middleware hasRole
is working but routeNeedsRole
not. Trying use as second parameter string, array, same effect - abort(403)
runs.
Because hasRole
is working this problem looks very strange for me.
composer dump-autoload
- used, not solve problem
in routes.php
Entrust::hasRole('superadmin');// => false
\Entrust::routeNeedsRole('admin/dashboard', ['superadmin'], abort(403, 'Forbidden'), false); // display 403 page
in middleware
\Entrust::hasRole('superadmin'); // => true
\Entrust::routeNeedsRole('admin/dashboard', ['superadmin'], abort(403, 'Forbidden'), false); // display 403 page
My model User.php
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword, EntrustUserTrait;
routes.php
Route::group([ 'prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['auth', 'admin']], function (){
Route::get('dashboard', [ 'as' => 'dashboard', 'uses' => "DashBoardController@index" ]);
});
I have also Role and Permission models looks like in Readme file https://github.com/Zizaco/entrust/tree/laravel-5
// sorry for my english.