dp13668681869 2018-11-02 20:18
浏览 155

用户字段在注册用户时显示为空

I added couple new columns to users table like role, suspended_at and banned_at. And then added them as fillable.

But when a new user is registered, the fields seems empty (except id,created_at and updated_at).

Here is the migration file

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string("username", 20)->unique()->index();
        $table->string('email')->unique();
        $table->string('password');
        $table->string("role",15)->default("newbie");
        $table->rememberToken();
        $table->timestamps();
        $table->dateTime("suspended_at")->nullable();
        $table->dateTime("banned_at")->nullable();
    });

User model

protected $fillable = [
        'name', 'email', 'password', "username", "role", "suspended_at", "banned_at"
    ];

a small demo from users table.

+----+------+----------+-------+----------+------+
| id | name | username | email | password | role |
+----+------+----------+-------+----------+------+
|  4 |      |          |       |          |      |
+----+------+----------+-------+----------+------+

RegisterController

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        "username" => $data["username"],
        'password' => Hash::make($data['password'])
    ]);
}
  • 写回答

1条回答 默认 最新

  • douchangmian0305 2018-11-03 06:32
    关注

    Shouldn't you add role, suspended_at, banned_at inside User::create to register. And also in your table you don't have suspended_at, banned_at column, please check once.

    Instead of using default registration I am suggesting you to create your own controller php artisan make:controller UserController then add a post-url to indicate/trigger the function like Route::post('/register', UserController@add_new_user) and then inside the controller you have to call the model by adding use App\User before class UserController extends Controller and inside the class create your own function like below:

    public function add_new_user(Request $request) {
      $user = new User; //modal
      $user->name = $request->name;
      $user->username = $request->username;
      $user->email = $request->email;
      .
      .
      .
      $user->save();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计