Reputation: 1599
I seem to have some inconsistent behaviour here... I'm working through some tutorials, dealing with displaying a user profile and then editing and updating the profile, using form model binding.
The problem is that the Html helper doesn't seem to generate the correct links behind the buttons. When I hover over the buttons, I get something different:
For example, on my edit blade, the SAVE button is supposed to lead to the update route. Hovering over the button shows it to be http://localhost/dev.rentid.co.nz/public/user/2
when I was expecting it to be http://localhost/dev.rentid.co.nz/public/user/2/update
Does Html::linkRoute
need some additional parameters?
My show blade
{!! Html::linkRoute('user.edit', 'Edit', array($thisUser->id), array('class' => 'btn btn-primary btn-block')) !!}
{!! Html::linkRoute('user.destroy', 'Delete', array($thisUser->id), array('class' => 'btn btn-danger btn-block')) !!}
My edit blade:
{!! Form::model($thisUser, ['route' => ['user.update', $thisUser->id], 'method' => 'PUT']) !!}
...
{!! Html::linkRoute('user.show', 'Cancel', array($thisUser->id), array('class' => 'btn btn-danger btn-block')) !!}
{!! Html::linkRoute('user.update', 'Save', array($thisUser->id), array('class' => 'btn btn-success btn-block')) !!}
...
{{ Form::close() }}
My routes.php
...
Route::resource('/user', 'UserController');
....
which produces this:
GET|HEAD | user | user.index | rentid\Http\Controllers\UserController@index
POST | user | user.store | rentid\Http\Controllers\UserController@store
GET|HEAD | user/create | user.create | rentid\Http\Controllers\UserController@create
DELETE | user/{user} | user.destroy | rentid\Http\Controllers\UserController@destroy
PUT|PATCH | user/{user} | user.update | rentid\Http\Controllers\UserController@update
GET|HEAD | user/{user} | user.show | rentid\Http\Controllers\UserController@show
GET|HEAD | user/{user}/edit | user.edit | rentid\Http\Controllers\UserController@edit
Upvotes: 0
Views: 378
Reputation: 9749
The resource routing uses REST, this means that the controller will handle the requested URL based on the type of the request.
Like you've displayed in your routes listing, the route user/{user} with a DELETE request will be handled by the destroy method, the route user/{user} with a PUT or PATCH request will be handled by the update method, so your URL http://localhost/dev.rentid.co.nz/public/user/2
is correct. Your update form is ok, but for the delete you have to also use a form to make the request.
{!! Form::open(['method' => 'DELETE', 'route' => ['user.destroy', $thisUser->id]]) !!}
<button type="submit">Delete</button>
{!! Form::close() !!}
Upvotes: 2