我在我的laravel应用程序中使用资源控制器,我正在尝试使用依赖注入,但它不适用于特定的模型和控制器.
这有效:
/**
* Display the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function show(Booking $booking)
{
return $booking;
}
Run Code Online (Sandbox Code Playgroud)
但出于某些令人愤怒的原因,这不是:
/**
* Display the specified resource.
*
* @param \App\SchoolEvent $schoolEvent
* @return \Illuminate\Http\Response
*/
public function show(SchoolEvent $schoolEvent)
{
return $schoolEvent;
}
Run Code Online (Sandbox Code Playgroud)
我的路线看起来像这样:
// Events
Route::resource('events', Resources\SchoolEventController::class);
// Bookings
Route::resource('bookings', Resources\BookingController::class);
Run Code Online (Sandbox Code Playgroud)
由于某种原因/预订/ 1返回填充的对象,但/ events/1返回空的对象.谁能告诉我为什么?