I'm using resource controllers in my laravel app and I'm trying to use dependancy injection but it's not working on a particular model and controller.
This works:
/**
* Display the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function show(Booking $booking)
{
return $booking;
}
But for some infuriating reason this doesn't:
/**
* Display the specified resource.
*
* @param \App\SchoolEvent $schoolEvent
* @return \Illuminate\Http\Response
*/
public function show(SchoolEvent $schoolEvent)
{
return $schoolEvent;
}
My Routes look like this:
// Events
Route::resource('events', Resources\SchoolEventController::class);
// Bookings
Route::resource('bookings', Resources\BookingController::class);
For some reason /bookings/1 returns a filled object but /events/1 returns an empty one. Can anyone tell me why?
Change the injected variable name to $event
to match the route parameter name {event}
:
public function show(SchoolEvent $event)
You can see the route parameters with this command:
php artisan route:list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With