doob0526 2013-03-27 13:12
浏览 19
已采纳

Laravel 4 - Eloquent质量分配在更新后创建空记录

I've just updated L4 (both skeleton and packages) to the latest version.

Now, when I try to create a new instance of one of the Models and save it to the DB, I get an empty record, except for the timestamps and the primary key.

This behaviour persists over all models (Users, Bids, Projects etc...) so It's not a local problem.

I tried both

Project::create($project);

and, following this thread:

$new_project = new Project;

$new_project->fill($project);

$new_project->save();

But the result is the same: an empty record.

  • 写回答

2条回答 默认 最新

  • dongsou4301 2013-03-29 11:15
    关注

    So, as it turns out from the docs Mass assignment is now blocked by default for security reasons (e.g fetching all data from the form without specifying the fields (Input::all()) and saving it as is to the DB might result in unwanted fields being assigned, in case the client manipulates the form by adding a field with a name that corresponds to the field in the DB).

    To designate the fields that are allowed to be assigned, one should either explicitly add the fields in question as a white-list to a protected $fillable array on the model, or alternatively, create a black-list using the $guarded array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊