当我使用验证请求时没有数据passet,这是错误消息
SQLSTATE [23000]:违反完整性约束:1048列经度'不能为空(SQL:更新settings
设置longitude
=,latitude
=,zoom
=,address
=,email
=,{{ 1}} =,tel
=其中about
= 1)
但没有它正确运行
迁移
id
规则方法
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->integer('longitude');
$table->integer('latitude');
$table->integer('zoom')->default(14);
$table->string('address');
$table->string('email');
$table->string('tel');
$table->text('about');
$table->timestamps();
});
}
更新方法
public function rules()
{
return [
'longitude'=>'required|numeric',
'latitude'=>'required|numeric',
'zoom'=>'required',
'address'=>'min:15',
'email'=>'required|email',
'tel'=>'required',
'about'=>'required',
];
}
刀片模板
use App\Http\Requests\SettingsFormRequest;
...
public function update(SettingsFormRequest $request, Settings $setting)
{
Settings::whereId($setting->id)->update([
'longitude'=>$request->validate()['longitude'],
'latitude'=>$request->validate()['latitude'],
'zoom'=>$request->validate()['zoom'],
'address'=>$request->validate()['address'],
'email'=>$request->validate()['email'],
'tel'=>$request->validate()['tel'],
'about'=>$request->validate()['about']
]);
return redirect(route('settings.index'));
}
答案 0 :(得分:0)
在SettingsFormRequest
中。确保延长FormRequest
class SettingsFormRequest extends FormRequest
{
public function authorize() //this is needed and return to true
{
return true;
}
public function rules()
{
return [
'longitude'=>'required|numeric',
'latitude'=>'required|numeric',
'zoom'=>'required',
'address'=>'min:15',
'email'=>'required|email',
'tel'=>'required',
'about'=>'required',
];
}
}
控制器中的
public function update(SettingsFormRequest $request, $id)
{
// mass assignment.. make sure you list necessary column in fillable array in Setting model
Settings::find($id)->update($request()->all());
return redirect(route('settings.index'));
}
全部......
答案 1 :(得分:0)
非常感谢你的配偶,在你的帮助下我找到了解决方案。 问题出在控制器中:
$request->validate()['variable']
只需删除验证方法并制作如下语句:
$request->variable