How to check if a user email already exist

0 votes
In laravel, when a new user is registering to my site and the email they use already exist in the database. how can tell the user that the email already exist ?
Dec 7, 2020 in Laravel by kartik
• 37,520 points
3,502 views

1 answer to this question.

0 votes

Hello @kartik,

The validation feature built into Laravel lets you check lots of things, including if a value already exists in the database. Here's an overly simplified version of what you need. In reality you'd probably want to redirect back to the view with the form and show some error messages.

// Get the value from the form
$input['email'] = Input::get('email');

// Must not already exist in the `email` column of `users` table
$rules = array('email' => 'unique:users,email');

$validator = Validator::make($input, $rules);

if ($validator->fails()) {
    echo 'That email address is already registered. You sure you don\'t have an account?';
}
else {
    // Register the new user or whatever.
}

);

Laravel has built-in human readable error messages for all its validation. You can get an array of the these messages via: $validator->messages();

Hope it helps!!

Thank You!!

answered Dec 7, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How to check if connected to database in Laravel?

Hello @kartik, You can use if(DB::connection()->getDatabaseName()) { echo ...READ MORE

answered Sep 28, 2020 in Laravel by Niroj
• 82,840 points
8,302 views
0 votes
1 answer

How to redirect to login if user is not authenticated in laravel?

Hello @kartik, Use middleware for this purpose and ...READ MORE

answered Oct 28, 2020 in Laravel by Niroj
• 82,840 points
8,807 views
0 votes
1 answer

How to Check for a Specific Type of Object in PHP?

Hello @kartik, Use: bool is_a ( object $object ...READ MORE

answered Oct 29, 2020 in Laravel by Niroj
• 82,840 points
975 views
0 votes
1 answer

How do you check if a field is not null with Eloquent?

Hello @kartik, Simply,we can use Model::whereNotNull('sent_at'); Or Model::whereRaw('sent_at is not null'); Thank ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,840 points
3,624 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
22,986 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,980 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,907 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,454 views
+1 vote
1 answer

How to check if a record already exists in a laravel?

Hey, As a newbie it is most common ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,840 points
32,676 views
0 votes
1 answer

How to check if a cookie is set in laravel?

Hello @kartik, You can change: @if (Cookie::get('cookiename') !== false) to @if ...READ MORE

answered Dec 7, 2020 in Laravel by Niroj
• 82,840 points
4,015 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP