Reputation:
So I am trying to get value from mysql and compare it to requested value, so I can avoid dublicates, what am I missing cause it's not working. Help plz
if ($request->email == DB::table('people')->where('email', $request->email)->get('email')){
return 'This e-mail is already registered';
}
//I get [{"email":"[email protected]"}] type(object)
Upvotes: 0
Views: 40
Reputation: 29413
Just check if the entry in the database exists directly using a query.
if (DB::table('people')->where('email', $request->email)->exists()){
return 'This e-mail is already registered';
}
https://laravel.com/docs/8.x/queries#determining-if-records-exist
Upvotes: 1