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

Categories

0 votes
870 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...