Reputation: 23
I want to create a registration form that includes username, Phone number and an address in the registration process. How do you edit the auth to add or delete fields for registration and login?
Upvotes: 1
Views: 3568
Reputation: 3679
first open RegisterController class to make some modifications
pathToYourApp/app/Http/Controllers/Auth/RegisterController.php
1- add your extra fields to validator
method
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'phone' => 'required|numeric',
// add another extra fields here
]);
}
2- now make this fields added to create statement by add extra fields to create
method
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
// add another extra fields here
]);
}
of course you should add your extra fields to your user migration
and add input fields in blade view
Upvotes: 0
Reputation: 1
1 update users table using migration
2 run migration
3 made changes in registration view
4 made changes in Auth Registration controller. In validation function and in register function.
Upvotes: 0
Reputation: 6115
As far as I understood your question, to delete/add fields correctly in Laravel's registration form, you will have to modify three different places:
Registration controller which is placed in /app/Http/Controllers/Auth/RegisterController.php
And you of course add the fields in the blade file so can send them through the form.
Upvotes: 2