I understand that if I have a route of say api/users/{id} then this will get passed to the controller function as an $id param.
However if I have a api route of:
Route::patch('roadmap/{roadmapcourse}', 'RoadmapCourseController@update');
and a controller method:
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\RoadmapCourse $roadmapcourse
* @return \Illuminate\Http\Response
*/
public function update(Request $request, RoadmapCourse $roadmapcourse)
{
$data = $request->validate([
'user_id' => 'required|integer',
'course_id' => 'required|integer',
'stage' => 'required|integer',
'title' => 'required|string',
'creator' => 'required|string',
'url' => 'required|string',
'hours' => 'required',
'completed' => 'required|boolean'
]);
$roadmapcourse->update($data);
return response($roadmapcourse, 200);
}
Then I send a request to http://projectname/api/roadmap/2 - then 2 gets passed through as the param to the update function doesn't it?
But by the looks of the update function its expecting an instance of RoadmapCourse and not a single digit i.e. '2'?
Does Laravel, behind the scenes, search for a database entry for a RoadmapCourse with the id of 2, and then bring that in to the function as $roadmapcourse?
That's the only thing I can think of, and I can't find any documentation explaining what's going on.
P.S I also can't find any documentation regarding the variable naming convention of Class $variable i.e. RoadmapCourse $roadmapcourse, I understand what it does, just can't find any docs.
P.P.S I also can't find any documentation explaining the "docblocks" above a controller method e.g.
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\RoadmapCourse $roadmapcourse
* @return \Illuminate\Http\Response
*/
And what these '@param' declarations are actually for??
Any help or links to docs would be appreciated (I've been looking at the Laravel docs but can't find any mention or any of these things - hence posting on here)
Thanks!