Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
863 views
in Technique[技术] by (71.8m points)

php - How to add new input in register page laravel?

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

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

1 Reply

0 votes
by (71.8m points)

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']),
    ]);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...