php - createorupdate 功能不起作用。填充模型缺少参数
问题描述
传递给 Illuminate\Database\Eloquent\Model::fill() 的参数 1 必须是数组类型,给定 null,
public function createOrUpdate(Staff $staff, Request $request)
{
$staff->fill($request->get('staff'))->save();
$staff->attachment()->syncWithoutDetaching(
$request->input('staff.attachment', [])
);
Alert::info('You have successfully Added a Member.');
return redirect()->route('platform.staff');
}
解决方案
key => value
在您的 fill() 方法中提供一个关联数组
public function createOrUpdate(Staff $staff, Request $request)
{
$staff->fill(['column_name' => $request->get('staff')])->save();
$staff->attachment()->syncWithoutDetaching(
$request->input('staff.attachment', [])
);
Alert::info('You have successfully Added a Member.');
return redirect()->route('platform.staff');
}
注意:确保您protected $fillable
有财产
推荐阅读
- swift - 让 NSButton 标题比它的图像宽
- android - 如何为用户选择更改 android studio 中项目的显示名称?
- sql-server - 如何将错误消息返回到我的存储过程?
- php - Laravel 5.8:你能帮我解决这个问题吗
- python - 如何打印过滤结果所在的行?
- javascript - 无法显示自举模式,只有背景
- python - 如何更改 tkinter 窗口标题的颜色而不将其从任务栏中删除?
- amazon-web-services - Terraform 不删除 rds 自动缩放的极光实例
- discord.js - 我如何为我的 id 和我的朋友 id 设置命令工作,例如。当我尝试这个时,它只适用于我的朋友 ID
- javascript - 如何根据javascript中字符串中的第一个单词过滤字符串数组?