I have a policy that checks if the authenticated user can delete a consultant.
Unfortunately, the response is always unauthorised, and I'm unsure why!
Policy function (ClinicConsultantPolicy):
public function delete(User $user, Consultant $consultant)
{
$consultant_clinic_id = $consultant->clinic_id;
return $user->clinic->id === $consultant_clinic_id;
}
Controller calling the above function (ClinicConsultantController):
public function destroy($id)
{
$consultant = Consultant::find($id);
$this->authorize('delete', $consultant);
Consultant::find($id)->delete();
return redirect('clinic/consultants');
}
If I output the two variables the policy is trying to match (user's clinic ID and the consultant's clinic id), both are equal to 2.
However, clearly one of them is either not 2, or perhaps undefined, when it reaches the policy, but I'm unsure why? Many thanks for your help.