php – 在laravel中保存表单数据
发布时间:2020-12-14 19:46:46 所属栏目:大数据 来源:网络整理
导读:现在我有一个包含gender,options和user_id的表单. 我的公共函数存储(Request $request)如下所示: public function store(Request $request){ $task = new Appointment; $task-gender = $request-gender; $task-options = $request-options; $task-user_id =
现在我有一个包含gender,options和user_id的表单.
我的公共函数存储(Request $request)如下所示: public function store(Request $request) { $task = new Appointment; $task->gender = $request->gender; $task->options = $request->options; $task->user_id = $request->user_id; $task->save(); } 这完全没问题,但这只是3个字段? 我发现了这个:$data = Input :: all();
您可以使用create()方法使用
mass assignment功能:
public function store(Request $request) { Appointment::create($request->all()); } 不要忘记在Appointment模型中填充$fillable数组中的所有列: protected $fillable = ['gender','options','user_id','another_one']; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |