I have the following model with fillable properties:
class Job extends Model {
protected $fillable = [
'job_type_id',
'user_id',
'start_at',
'end_at',
'job_title',
'job_ref',
'job_desc'
];
// other stuff
}
I have a form to update the job which includes some multiselect dropdown lists as follows:
<div class="form-group ">
<label for="job_title">Job title</label>
<input id="job_title" class="form-control" type="text" name="job_title">
</div>
<div class="form-group ">
<label for="industry_list">Industry</label>
<select id="industry_list" class="form-control name="industry_list[]" multiple="" >
<option value="1">Accounting</option>
<option value="37">Administration</option>
...
</select>
</div>
In my controller I have the following method to update the job but I get error:
ErrorException in helpers.php line 671: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
It seems like using Auth::user()->jobs()->update($request->except('job_type_id'));
is causing this error because the request object contains an array for the industry_list. But why should this matter as I've defined the mass fillable attributes on the Job class?
public function update(JobRequest $request, $id)
{
$job = Job::findOrFail($id);
Auth::user()->jobs()->update($request->except('job_type_id'));
$job->industries()->sync($request->input('industry_list'));
flash()->success('Job details have been updated');
return redirect('/job/' . $id . '/edit');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire