Reputation: 6679
I cant seem to get my edit function to work in my resourceful controller. This is my controller:
class UserController extends Controller{
public function index()
{
return view('testindex');
}
public function test(){
return 'test';
}
public function edit(User $user){
return 'test2';
}
public function create(){
return 'test3';
}
}
And my routes:
Route::post('test','UserController@test');
Route::resource('/','UserController');
Which mean that edit should be in the resource controller.
Create works but edit isn't, it gives me a
NotFoundHttpException
This is the form:
<a href="{{$id}}/edit">Edit</a>
And yes, the variable $id
works and is showing in the url.
What am I doing wrong here?
Upvotes: 0
Views: 50
Reputation: 35180
This is because you're not naming the resource i.e.
Route::resource('user', 'UserController');
To get around this you will need to change you route to be:
Route::resource('/', 'UserController', ['parameters' => [
'' => 'user'
]]);
(The above will allow you to keep your urls the same).
Please note that you will have to keep this Route
at the bottom of your file.
Hope this helps!
Upvotes: 1