Michael
Michael

Reputation: 576

Laravel 5.6 opening a form with laravel collective for named route with id

my route:

$this->post('imagerequests/{id}/save-building', 'ImageRequestController@saveBuildingImage')->name('saveBuildingImage');

my opening form:

{{ Form::open(array('route' => ['saveBuildingImage' => $imageRequest->id])) }}

When I dd($imageRequest) I see the id in the attributes so no problem there.

error message:

Undefined offset: 0 in FormBuilder.php line 1160

Upvotes: 0

Views: 659

Answers (2)

Michael
Michael

Reputation: 576

Found the issue to fix it using Laravel Collective

{{ Form::open(array('route' => array('saveBuildingImage', $imageRequest->id))) }}

Upvotes: 0

Mahdi Jedari
Mahdi Jedari

Reputation: 758

Laravel's route expects the $id variable. But in the view, you didn't send variable name. Without using Laravel collective package notation you should use in this form to pass data:

route('saveBuildingImage', ['id' => $imageRequest->id]);

Upvotes: 1

Related Questions