php - Laravel 用户::创建缺失数据

标签 php mysql laravel

我已经使用迁移来更新我的用户表以包含提交的用户名,但在注册时该字段未填充到数据库中:

    $input = Input::only(['name', 'username', 'email', 'password']);
    $input['password'] = Hash::make($input['password']);
    User::create($input);
    return Redirect::to('login');

帖子转储提供了这个:

array (size=4)
  'name' => string 'Joe Bloggs' (length=13)
  'username' => string 'jbloggs' (length=12)
  'email' => string 'jbloggs@gmail.com' (length=24)
  'password' => string '$2y$10$whgTTwa5g.du/WJfJGhGtO******SYTerzL4bhOuedW4C' (length=60)

但是用户名字段始终为空。没有错误或警告。我试过回滚和重新迁移,但没有任何变化。

我错过了什么吗?谢谢!

最佳答案

您传递给create 的所有属性都需要在$fillable 数组中定义,以便您可以将它们用于mass assignment

在你的情况下:

protected $fillable = array('name', 'username', 'email', 'password');

或者你也可以定义相反的,一组 guarded 属性:

protected $guarded = array('foo', 'bar');

关于php - Laravel 用户::创建缺失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27740032/

相关文章:

php - 以 POST 请求发送删除操作

php - Laravel:静态::创建与数据库:插入

php - 如何使用 PHP 和 MySQL 创建编辑表单以更新 HTML 表单中的记录

c# - 将 MySql 与 EntityFramework 5.0、SimpleMembership 一起使用,多个错误

php - 安装 laravel --prefer-dist

php - 这个多重可选过滤器的最佳解决方案是什么?

php - 无法使用指定的键从数据库访问解码的 json 数据

PHP 和 mySQL 不工作

MySQL:按两列分组而不考虑顺序

PHP 正则表达式 : match text urls until space or end of string