【问题标题】:Laravel: Get value of radiobutton in blade and put it in database with AuthController.phpLaravel:获取刀片中单选按钮的值并使用 AuthController.php 将其放入数据库
【发布时间】:2016-09-02 00:52:29
【问题描述】:

因此,在使用 AuthController 将单选按钮的值放入数据库时​​遇到问题。我只想让用户在 Laravel 注册表单(register.blade.php)中选择男性、女性和其他(值 1,2 和 9)。 但无论我尝试什么,我的值都会在我的数据库中返回 0。

这是我的刀片:

{{ Form::radio('sex', 1, true, ['class' => 'grid__offset-bp1-2']) }}male<br>
{{ Form::radio('sex', 2, false, ['class' => 'grid__offset-bp1-2']) }}female<br>
{{ Form::radio('sex', 9, false, ['class' => 'grid__offset-bp1-2']) }}other

这是我的 AuthController.php:

protected function create(array $data)
    {
        return User::create([
            'name_first' => $data['name_first'],
            'name_second' => $data['name_second'],
            'name_last' => $data['name_last'],

            'sex' => $data['sex'],

            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            //'birthday' => $data['birthday'],
            'phone' => $data['phone']
        ]);
    }

【问题讨论】:

  • 有很多地方可能会出错,而您没有向我们展示控制器逻辑。

标签: php html laravel blade


【解决方案1】:

你能告诉我们用户模型吗? 也许你忘记了 Model 中的“sex”字段

【讨论】:

  • 谢谢!我忘了把 'sex 放在可填充(user.php)中
猜你喜欢
  • 2020-04-09
  • 2017-01-02
  • 2012-07-08
  • 1970-01-01
  • 2015-11-10
  • 2014-08-22
  • 2019-06-26
  • 2013-05-04
  • 2015-07-10
相关资源
最近更新 更多