I Get this error every time I create an edit button or even a button to view a particular post in my project.
Here's my route code:
Route::get('/posts/edit/{photographers}', 'PhotographerController@edit')
->name('photographers.edit');
Here's my edit function in the controller file :
public function edit(Photographer $photographer)
{
return view('photographers.edit', compact('photographer'));
}
Here's my view button route:
<a href="{{route('photographers.edit', $photographer)}}">Edit</a>
I read a lot of previous posts on this issue but didn't really help me.
CodePudding user response:
sometimes the dependency injection can be the cause of the error, you can use id as follows
public function edit($id)
{
$photographer = Photographer::find($id);
return view('photographers.edit', compact('photographer'));
}
I also noticed in your blade file, you are passing the entire $photographer as an argument, you only need to pass the id
<a href="{{route('photographers.edit', $photographer->id)}}">Edit</a>