1

I'm trying to use policy on a route group. I've included the bindings middleware and tried to list the ACTION and MODEL in the CAN middleware.

For some reason it keeps returning 403. Probably I didn't quite understood how the policies work.

I'm trying to enter the before method in the policy but It keeps returning 403. Also it would be lovely if someone explains how exactly should I list custom methods in the middleware.

I also did register my policy in the AuthServiceProvider


  protected $policies = [
        Service::class => ServicePolicy::class,
    ];

    public function before(CustomAuth0User $user, Service $service)
    {
        dd($service);
    }

 Route::group(['prefix' => 'services', 'namespace' => 'Services', 'middleware' => ['bindings', 'can:getCancel, service']], function () {
        Route::get('/{service}/cancel', 'ServiceController@getCancel');
        Route::post('/{service}/cancel', 'ServiceController@postCancel');

        Route::get('/{id}/reassign', 'ServiceController@getReassign');
        Route::post('/{id}/reassign', 'ServiceController@postReassign');

        Route::get('/{id}/close', 'ServiceController@getClose');
        Route::post('/{id}/close', 'ServiceController@postClose');

        Route::get('/{id}/history', 'ServiceController@getHistory');
    });

Controller


 public function getCancel(Service $service)
    {
        dd($service);
    }
Kristian Vasilev
  • 504
  • 8
  • 26

0 Answers0