【发布时间】:2016-09-15 14:38:20
【问题描述】:
我正在尝试在我的数据库中存储一系列县。这是我的刀片:
<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')。
标签: php laravel multiple-select