Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to add a new field on Laravel's register page that's store the new data in my database. still learning Laravel so basically, i am a newbie. I need help on this, Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
860 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is simple as adding a new field in database and form. Go through the basic documentation of Laravel before jumping into it.

Basically, follow these steps:

1) Add a new column to your database table (ie: 'users' table)

ALTER TABLE `users` ADD `address` TEXT NOT NULL AFTER `name`;

(This is just a raw format to add the field for a basic user, Best way to add field is to use laravel migration)

2) Add an input field to registration form page (register.blade.php)

<input id="address" type="text" class="form-control" name="address" value="{{ old('address') }}" required>

3) Make change on your RegisterController.php

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'address' => $data['address'],
        'password' => bcrypt($data['password']),
    ]);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...