Monday, March 20, 2017

Laravel dependency injection not working

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?



via IainChambers

Advertisement