Reputation: 463
Working on trying to get the following form's URL to populate properly. Been stumbling over this for some time so here for some help.
As you can see from the following code, I am opening the form - binding the model - and trying to set the URL dynamically. the full URL is something like {username}/account/cards/id so i need to pass it the username (which i would like to pass the authenticated user (as they would only have access to their own page) and the ID of the card they are trying to update.
{!! Form::model($card, ['method' => 'PATCH', 'action' => 'Account\CardsController@update', array(Auth::user()->username, $card->id) ]) !!}
Now this is all happening in blade (front end) so not 100% what i am doing wrong. I have tried action, url, route... I can not get anything to work for some reason. Error I am getting on this one specifically is a array to string error. But if I can't build an array how do i pass in multiple variables? So a bit confused here.
any help would be appreciated.
Thanks
Citti
Upvotes: 1
Views: 1366
Reputation: 538
If I'm not mistaken, the action should be an array if you are passing variables through to the controller. Ex:
{!! Form::model($card, array('method' => 'PATCH', 'action' => array('Account\CardsController@update', Auth::user()->username, $card->id))) !!}
Not sure if you are using Larvel Collective HTML and Forms, but they are essentially the same as the Laravel version. This page: http://laravelcollective.com/docs/5.0/html#form-model-binding explains more about your particular use case.
Hope it helps.
P.S. Try adding:
{!! Form::hidden('_method', 'PATCH') !!}
...underneath the open tag instead of within it. This has to do with L5 method spoofing, and is generally necessary for anything that is not 'POST' or 'GET', I believe. (i.e., 'PUT', 'PATCH', and 'DELETE')
Upvotes: 0
Reputation: 1525
This is an update to my previous answer. You can try this one:
{!! Form::model($card, ['method' => 'PATCH', 'action' => [ 'Account\CardsController@update', Auth::user()->username, $card->id] ]) !!}
Upvotes: 2
Reputation: 6319
You're just passing your route parameters as an option to the Form::model
tag, not the route. Try:
{!! Form::model($card, ['method' => 'PATCH', 'action' => [ 'Account\CardsController@update', [Auth::user()->username, $card->id] ] ]) !!}
If you're still having trouble I would suggest you name your route and reference the named route in the action.
Upvotes: 0