Reputation: 183
I'm studying Laravel CRUD routing. Yesterday I post my problem, and many people helped me. In my case, I use Mr.Dasun Tharanga's answer and solved.
Is there easyest way to change 'resouce' name in web.php [Laravel9]
It works really nicely, but at edit page I got this error.
Missing required parameter for [Route: ddd.update] [URI: ddd/{ddd}] [Missing parameter: ddd]
When I roll backed as original 'students' it works. I checked controller and model route, but I couldn't figure out the cause. Could someone please teach me how to fix this?
Here is my current web.php
web.php
Route::resource('ddd', StudentController::class);
edit.blade
<form method="post" action="{{ route('ddd.update', $student->id) }}" enctype="multipart/form-data">
StudentController.php
public function edit(Student $student)
{
return view('edit', compact('student'));
}
LIST
GET|HEAD ddd ...................................................................... ddd.index › StudentController@index
POST ddd ...................................................................... ddd.store › StudentController@store
GET|HEAD ddd/create ............................................................. ddd.create › StudentController@create
GET|HEAD ddd/{ddd} .................................................................. ddd.show › StudentController@show
PUT|PATCH ddd/{ddd} .............................................................. ddd.update › StudentController@update
DELETE ddd/{ddd} ............................................................ ddd.destroy › StudentController@destroy
GET|HEAD ddd/{ddd}/edit ............................................................. ddd.edit › StudentController@edit
Before I change web.php the working edit page url is like this
http://127.0.0.1:8000/students/5/edit
Upvotes: 0
Views: 51
Reputation: 2315
As my answer in your old question, you can consider to name resource route parameters
in Web.php
Route::resource('fun_student', StudentController::class)->parameters([
'ddd' => 'student'
]);
Or you can choose another way that is changing the name of the argument in edit method.
public function edit(Student $ddd)
{
return view('edit', compact('ddd'));
}
Remember when you put a model instance as an argument of the controller method, the route segment name has to be the same to the name of argument of the controller method. Reference https://laravel.com/docs/10.x/routing#implicit-binding
Upvotes: 3