dongshi2458 2015-01-02 09:36
浏览 72
已采纳

Laravel用户::创建缺失数据

I've used a migration to update my users table to include a username filed, but on signup the field isn't populated in the database:

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

A dump of the post provides this:

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)

However the username field is always blank. No errors or warnings. I've tried a rollback and re-migrating, but there is no change.

Am I missing something? Thanks!

  • 写回答

2条回答 默认 最新

  • dongwalun2507 2015-01-02 09:42
    关注

    All attributes you pass to create need to be defined in the $fillable array so you can use them for mass assignment

    In your case:

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

    Alternatively you could also define the opposite, a set of guarded attributes:

    protected $guarded = array('foo', 'bar');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。