简体   繁体   中英

Why does Laravel only write email, created_at and updated_at variables to database when registering a user?

I installed Laravel Breeze in my Laravel 8 installation so I could easily get a user sign-up and registration system up and running. There is one problem that I'm having with this that I can't seem to solve.

When a user signs up, they enter their name, email and password (along with a confirmation of the password.) But only the email address and the created_at and updated_at timestamps are written to the users table, and I can't seem to figure out why. The store function in the RegisteredUserController.php file looks like this:

public function store(Request $request)
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'confirmed', Rules\Password::defaults()],
        ]);
        echo $request->name;
        echo $request->email;
        echo $request->password;
        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ]);

        event(new Registered($user));

        Auth::login($user);

        return redirect(RouteServiceProvider::HOME);
    }

Any help with this would be greatly appreciated.

in your User model check the $fillable variable have name and password

protected $fillable = [
    'name',
    'email',
    'password',
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM