Hi all,
Im quite new to laravel and Im building an API and have hit a road block with policies. Here is my challenge:
I have a api to delete a proposal and I need the owner of proposals to be the only ones that can delete it. After some research I found policies and I have implemented it as suggested by the docs but I keep getting this error:
Too few arguments to function App\Policies\ProposalPolicy::delete(), 1 passed in /..../vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 798 and exactly 2 expected",
"exception": "ArgumentCountError"
Now, this makes sense because the delete function has a signature with 2 parameters:
public function delete(User $user, Proposal $shareProposal)
{
//
}
however my understanding is that the current Auth user is inferred and passed along side the second parameter; but this doesnt work.
Im hooking this up in the api.php class like this:
Route::delete('proposal/delete/{id}', [ProposalController::class, 'destroy'])->can('delete', 'App\Models\Proposal');
As it seemed only one param was added in the ->can(...) call, I decided to add an array like this:
Route::delete('proposal/delete/{id}', [ShareProposalController::class, 'destroy'])->can('delete', ['App\Models\Userr', 'App\Models\ShareProposal']);
this did not work too. I also tried the different variations with the ->middelware(...) call, but didnt work either.
I also understand this call can be made from the controller with the ..authorise(...) call but could someone please help explain how this is expected to work in the routes as this is the desire location for this setup.
Thank you.