You can adjust the route to just the doctor like so
Route::get('bookings/{docter}', function (Docter $docter) {
return BookingResource::collection($doctor->bookings()->get());
});
Both solutions are fine, it just depends on your needs ;)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a component where I fetchBookings() for through an API route, and Echo.private all BookingCreated for $doctor, through an authenticated broadcast channel.
Through the API route I fetch all Bookings, but actually only want to fetch $doctor->bookings()
BookingListComponent.vue <booking-list :doctor="{{ $doctor }}"></booking-list>
<template>
<div>
<div class="row">
<div v-for="booking in bookings">
<booking :booking="booking"></booking>
</div>
</div>
</div>
</template>
<script>
export default {
props: ['doctor'],
data() {
return {
bookings: [],
}
},
created() {
if (!this.bookings.length) {
this.fetchBookings();
}
Echo.private(`Bookings.${this.doctor.id}`)
.listen('BookingCreated', (e) => {
this.fetchBookings();
});
},
methods: {
fetchBookings(){
axios.get('/api/bookings').then(response => this.bookings = response.data.data);
}
}
};
</script>
api.php
Route::get('bookings', function () {
return BookingResource::collection(Booking::all());
// here I get all Bookings, but actually only need to fetch $doctor->bookings()
});
Is this possible through an Api route, to get $doctor, or should I just turn the bookings prop into:
data(){
return{
bookings: this.doctor.bookings
}
}
You can adjust the route to just the doctor like so
Route::get('bookings/{docter}', function (Docter $docter) {
return BookingResource::collection($doctor->bookings()->get());
});
Both solutions are fine, it just depends on your needs ;)
Please or to participate in this conversation.