I'm trying to create a form in laravel to update some data. I started off by using the following in my blade template to fill the form with data from a model:
{{ Form::model($sensor, array('action' => 'settingsController@editSensor', $sensor->s_id)) }}
$sensor is send to the view from the controller in this way:
return view('settings.sensors.edit')->with('sensor', App\Sensor::find($sensorId))
The documentation isn't to clear about whether or not I also need to use Form::open , but the form open tag was already created, so I figured this would be enough.
In my routes I have these routes:
Route::get('/settings/sensors/edit/{sensorId}',['as' => 'sensor.edit', 'uses' => 'settingsController@editSensor']);
Route::post('/settings/sensors/edit/{sensorId}',['as' => 'sensor.edit', 'uses' => 'settingsController@editSensor']);
I could access the form by going to a url like http://localhost:8000/settings/sensors/edit/105 , the prefilling with data from the model worked like a charm.
The problem I had was that the submit button did now work. It would submit to http://localhost:8000/settings/sensors/edit/%7BsensorId%7D Clearly, the sensorId parameter was not being substituded properly.
I rewrote the Form::model function call after some googling to this:
{{ Form::model($sensor, array('route' => route('sensor.edit',$sensor->s_id)), $sensor->s_id) }}
When I now open the page, I directly get this error: Route [http://localhost:8000/settings/sensors/edit/105] not defined
That seems odd, since I made no change to the routes, and there is a route defined for this url. Any idea where I'm going wrong?