jeudi 11 juin 2020

Laravel - model policy in some routes not working

In a revision work - Laravel 5.8 - I'm facing a strange behavior:

app » Policies » CustomerPolicy

public function create(User $user )
{
    dd($user);  //  for debugging purposes          
}
... 
public function update(User $user, Customer $customer)
{
    dd($customer);  //  for debugging purposes      
}
...

Registering the policy
app » Providers » AuthServiceProvider

protected $policies = [
    Customer::class => CustomerPolicy::class,
    // TRIED ALSO:   'App\Customer' => 'App\Policies\CustomerPolicy',
];

routes » web

Route::get( 'customers/create', 'CustomerController@create')->name( 'customers.create' )->middleware( 'can:create,customer' );
...
Route::get( 'customers/{customer}/edit', 'CustomerController@edit' )->name( 'customers.edit' )->middleware( 'can:update,customer' );   
Route::patch( 'customers/{customer}', 'CustomerController@update')->name( 'customers.update' )->middleware( 'can:update,customer' ); 

The strange thing is: the above first route - 'customers/create' - doesn't work, trying to access the page gets a 403 / forbidden code. But the other two - 'customers.edit', 'customers.update' - work as expected !!?!.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hbKI86
via IFTTT

Aucun commentaire:

Enregistrer un commentaire