mardi 1 novembre 2016

Laravel authorization via middleware

I created a policy in laravel 5.3 with this two actions:

class ProjectPolicy {
   ...
   public function index(User $user)
   {
      return true;
   }
   public function create(User $user)
   {
      return true;
   }
   ...
}

and then I tried to make authorization via route group middleware:

Route::group(['middleware' => ['can:index,create,App\Project']], function () {
    Route::resource('projects', 'ProjectController');
});

ofcourse I have created Project model and controller correctly, but calling index and create actions always returns 403 forbidden response. where is the problem?

Update:

removing one of actions from route middleware, results correct response. something like this:

Route::group(['middleware' => ['can:index,App\Project']], function () {
    Route::resource('projects', 'ProjectController');
});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire