Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 Form passing 2 parameters

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

like image 755
SaschaDens Avatar asked Sep 16 '13 15:09

SaschaDens


1 Answers

Try this:

Form::open(array('class' => 'form-horizontal', 'method' => 'put', 'action' => array('TankController@update', $aid, $id)))
like image 56
Antonio Carlos Ribeiro Avatar answered Sep 27 '22 16:09

Antonio Carlos Ribeiro