当我试图将所有选定的值插入到数据库中时,我得到[ result in driver_lisence column。
这是我的刀片
<div class="form-group col-sm-6">
<label>{{__('driver.driver_licence')}}</label>
<select name="driver_lisence[]" class="form-control select multiple" id="" multiple="multiple">
<option {{ old('driver_lisence') == 'A' ? 'selected': '' }} value="A">A</option>
<option {{ old('driver_lisence') == 'B' ? 'selected': '' }} value="B">B</option>
<option {{ old('driver_lisence') == 'C' ? 'selected': '' }} value="C">C</option>
<option {{ old('driver_lisence') == 'D' ? 'selected': '' }} value="C">D</option>
<option {{ old('driver_lisence') == 'E' ? 'selected': '' }} value="E">E</option>
</select>
@error('driver_lisence')
<label id="with_icon-error" class="validation-invalid-label" for="with_icon">
{{$message}}
</label>
@enderror
</div>这是我的模型
protected $fillable = [
'firstname',
'lastname',
'birthday',
'email',
'phone',
'password',
'gender',
'image',
'pasport_id',
'fin_code',
'driver_lisence',
'status',
'fcm_token',
'driver_group_id',
'app_version',
];
protected $casts = [
'driver_lisence' => 'array'
];这是我的控制器
public function store(DriverRequest $request)
{
$data = $request->all();
if ($request->file('image'))
{
$data['image'] = request('image')->store('',['disk' => 'uploads']);;
}
$data['password'] = Hash::make($data['password']);
Driver::create($data);
return redirect(route('admin.driver.index'))->with(_sessionmessage());
}我只想选择所有值并像数组一样插入到driver_licence列中。
发布于 2020-06-01 09:37:32
我自己修好的。问题出在我的迁移过程中。在这里,我插入了第1栏。我把它删除了,然后我就可以工作了。
https://stackoverflow.com/questions/62123611
复制相似问题