Reputation: 113
Currently i'm working on a project to manage my cost on fuel.
Now i try to pass 2 parameters in a Form::open()
which sadly doesn't work.
The reason why i think i need to pass 2 parameters at once is because my url is Sitename/car/{id}/tank/{id}
What am i doing wrong?
edit.blade.php
Form::open(array('class' => 'form-horizontal', 'method' => 'put', 'action' => array('TankController@update', array($aid, $id))))
Problem Code
'action' => array('TankController@update', array($aid, $id)
-Results in the following error:
Parameter "tank" for route "car.{id}.tank.update" must match "[^/]++" ("" given) to generate a corresponding URL.
TankController.php
public function edit($id, $tid)
{
$tank = Tank::find($tid);
if(!$tank) return Redirect::action('TankController@index');
return View::make('Tank.edit', $tank)->with('aid', $id);
}
public function update($id, $tid)
{
$validation = Validator::make(Input::all(), Tank::$rules);
if($validation->passes()){
$tank = Tank::find($tid);
$tank->kmstand = Input::get('kmstand');
$tank->volume = Input::get('volume');
$tank->prijstankbeurt = Input::get('prijstankbeurt');
$tank->datumtank = Input::get('datumtank');
$tank->save();
return Redirect::action('TankController@index', $id)->with('success', 'Tankbeurt succesvol aangepast');
} else return Redirect::action('TankController@edit', $id)->withErrors($validation);
}
Route.php
Route::resource('car', 'CarController');
Route::resource('car/{id}/tank', 'TankController');
Route::controller('/', 'UserController');
-Url Structure SITENAME/car/2/tank/2/edit
I've also looked into the api documents but found nothing. http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html
Thanks in advance
Upvotes: 5
Views: 17311
Reputation: 338
Try to use in your blade:
For Laravel 5.1
{!! Form::open([
'route' => ['car.tank.update', $car->id, $tank->id],
'method' => 'put',
'class' => 'form-horizontal'
])
!!}
Upvotes: 0
Reputation: 5230
This is the best solution
Form::open (array ('method'=>'put', 'route'=>array($routeName [,params...]))
An example:
{{ Form::open(array('route' => array('admin.myroute', $object->id))) }}
https://github.com/laravel/framework/issues/491
Upvotes: 3
Reputation: 87719
Try this:
Form::open(array('class' => 'form-horizontal', 'method' => 'put', 'action' => array('TankController@update', $aid, $id)))
Upvotes: 16