We know that Laravel 8 and above has an Implicit Binding function on its routes. I have tried to create a controller resource with model name is QuestionHelper
. When I define route with Route resource like below
use App\Http\Controllers\QuestionHelperController;
Route::resource('questionhelper', QuestionHelperController::class);
Unfortunately the implicit binding function doesn't work on the show, edit, update, and delete methods. When I access the show page for example, the data from the implicit binding is empty.
// When I access this method, the $questionHelper variable is empty
public function show(QuestionHelper $questionHelper)
{
return view('questionhelper.show', compact('questionHelper'));
}
Or shown an error when I access edit method with update method included in edit page.
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: questionhelper.update] [URI: admin/questionhelper/{questionhelper}] [Missing parameter: questionhelper]. (View: /var/www/resources/views/questionhelper/edit.blade.php)
Why is this happening? Whereas in other models like Category which only has one word works well.
Thank you.
CodePudding user response:
/**
* $parameter, is $id;
*
**/
<a href="{{ route('questionhelper.update', $parameter)}}"></a>
CodePudding user response:
I solved it.
If the model name more than 2 words (in this case QuestionHelper
) , so basically we need to name our resource name to questionHelper
instead of questionhelper
Hm I didn't know that before