I have business
and profile
models in my Laravel app. A business hasOne
profile.
I've created a patch method form using the form builder to update my business and profile tables.
Blade
{!! Form::model($business, ['route' => ['business.edit.post', $business], 'method' => 'PATCH']) !!}
@include('forms.business.edit')
{!! Form::close() !!}
BusinessController
public function update(Request $request, $id)
{
$business = Business::findOrFail($id);
$business->update($request->all());
$business->profile()->update($request->all());
return back()->withMessage('updated');
}
Now using a patch method will include a hidden field called _method along with the built in _token field for csrf protection.
I am getting an error when it updates the profile
model stating:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method' in 'field list' (SQL: update `business_profiles` set `_method` = PATCH, `_token` = Zyxtxa88uUQKhaRQNY8k7qPu2N0i6o20dY4sUABk, `city` = Belfast where `business_profiles`.`business_id` = 107 and `business_profiles`.`business_id` is not null)
It appears to me its trying to update those hidden fields when it shouldn't. When commenting out the _profile->update
line the save works fine. It looks like updating related Models does not adhere to the mass assignment rules built into Laravel. Could someone advise how to fix this?