php - laravel5 中的 MassAssignmentException

标签 php laravel-5 eloquent

我使用 laravel5...并且想要将数据存储在数据库中,当按下提交时出现此错误

> MassAssignmentException in C:\xampp\htdocs\marriage\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php line 417: _token

我的 Controller 代码

public function store(Request $request)
{
    $custom =Request::all();
    Custom::create($custom);

    return redirect('custom');

}

型号代码

class custom_table extends Model
{
  protected $fillable=[
    'skin_color',
    'cast',
    'residence',
    'family_members',
    'hieght',
    'created_at',
    'updated_at'
];

}

请帮我解决这个错误

最佳答案

您遇到了该错误,因为您的请求正在传递“_token”属性,并且它不可批量分配。

您可以使用 except 方法排除它,如下所示:

public function store(Request $request)
{
    $custom = Request::except('_token'); // Exclude _token attribute
    Custom::create($custom);

    return redirect('custom');

}

关于php - laravel5 中的 MassAssignmentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31651529/

相关文章:

java - 页面滚动时滚动模态框

php 图片从png创建

php - 如何修复 “Object of class stdClass could not be converted to string” : Laravel 5.4

laravel - 为什么 eloquent 在 FK 名字后面加下划线?

php - 如何按多列对 Laravel 查询构建器结果进行排序?

php - Laravel 根据枢轴额外字段从枢轴附加/分离模型

javascript - 避免在 Woocommerce 感谢页面中加载脚本

php - 无法写入只读 SQLite 数据库文件

php - 使用范围和关系计算两行 (Laravel)

javascript - Laravel 5.2 - vue 集成