If I have an API-route like:
Route::get('doctor/patients/{doctor}', function (Doctor $doctor) {
return UserResource::collection($doctor->patients()->orderBy('created_at', 'desc')->take(20));
});
to take e.g. 20 patients a doctor has, and I am logged in as the doctor (id: 1), I can use the API-route to display the patients.
Component:
methods: {
takePatients(){
axios.get('/api/doctor/patients/' + this.doctor.id).then(response => this.patients = response.data.data);
}
}
Now, if I visit /api/doctor/patients/1 I get those patients in JSON format from the DB.
The problem is, if I change the 1 to 2 in the url, I get 20 patients in JSON format from the doctor with the (id: 2), still logged in as doctor (1).
What do I need to add, to restrict this behavior?