每次我創建一個編輯按鈕甚至一個按鈕來查看我的專案中的特定帖子時,我都會收到此錯誤。
這是我的路線代碼:
Route::get('/posts/edit/{photographers}', 'PhotographerController@edit')
->name('photographers.edit');
這是我在控制器檔案中的編輯功能:
public function edit(Photographer $photographer)
{
return view('photographers.edit', compact('photographer'));
}
這是我的查看按鈕路線:
<a href="{{route('photographers.edit', $photographer)}}">Edit</a>
我在這個問題上閱讀了很多以前的帖子,但并沒有真正幫助我。
uj5u.com熱心網友回復:
有時依賴注入可能是導致錯誤的原因,您可以使用 id 如下
public function edit($id)
{
$photographer = Photographer::find($id);
return view('photographers.edit', compact('photographer'));
}
我還注意到在您的刀片檔案中,您將整個 $photographer 作為引數傳遞,您只需要傳遞 id
<a href="{{route('photographers.edit', $photographer->id)}}">Edit</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/379614.html
標籤:php sql 拉拉维尔 laravel-blade laravel-6
