我想在我的數據庫中存儲縣的數組。這裏是我的刀片:從選擇字段存儲數組
<select size="5" name="county[]" multiple class="form-control-2">
<option value="" selected="" disabled="">All Counties</option>
@if (isset($counties))
@foreach ($counties as $c)
<option value="{{ $c->name }}">{{ $c->name }}</option>
@endforeach
@endif
和我的控制器:
// Store the property Alert
public function propertyAlert(PropertyAlertRequest $request)
{
$action = PropertySubscribe::create($request->all());
$action = PropertySubscribe::create([
$action->county = Input::get('county'),
]);
$action->save();
notify()->flash('Registered!', 'success', ['text' => 'You have now been registered.']);
return back();
}
,我得到的錯誤是:
preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
誰能幫助我瞭解我是什麼做錯了?我將它作爲數組發送,並且dd正在顯示值。我是否需要對數組項目進行foreach?
爲什麼與依賴注入混個門面?你有注入的$ request,所以你不需要使用'Input ::'。使用'$ request-> input('county')'。 – Devon