Reputation: 310
Here is my Resource route:
Route::resource('projects','ProjectsController');
This is the Url I am requesting for edit from a view the project with id
projects/$project->id/edit/
Now how will I get the parameter
$project-id
form the Url into my ProjectsController edit() method with Request $request or other method ?
Upvotes: 1
Views: 254
Reputation: 4992
You have to have Route Handler In Your Contttroller:
public function edit(Request $request, $id ){
$project = Project::findOrFail($id)
...
[DO Whatewer You Want]
}
Upvotes: 1
Reputation: 3847
You can also take advantage of the implicit model binding:
public function edit( Project $project ){
//$project is your model instance
}
More on this topic here: https://laravel.com/docs/5.8/routing#implicit-binding
Upvotes: 0
Reputation: 2735
Try this:
public function edit( $id ){
$project = Project::find($id)
[...]
}
Upvotes: 0