Support the ongoing development of Laravel.io →
Authentication Validation
Last updated 2 years ago.
0

try that ...

public function loginpost(Request $request)
{
       
  $field = filter_var($request->input('email'), FILTER_VALIDATE_EMAIL) ? 'email' : 'phone';

   if(Auth::attempt([$field=> $request->input('email'), 'password' => $request->input('password')], true))
     {
              return 'you are logged in';
      }
       else
       {
             return 'error';
        }
        
    }
Last updated 9 years ago.
0

Thanks! That takes care of part of my problem.

I currently have a more verbose solution in place at the moment. Granted its not very elegant, but it works for now, and fulfils my workflow / response requirements.

$email = Validator::make($request->all(), [
    'identity' => 'required|email|exists:users,email|min:5|max:100',
]);

$phone = Validator::make($request->all(), [
    'identity' => 'required|regex:@\+\d{1,3}\s{1}\d{3,4}\s{1}\d{6,8}@|exists:users,phone|min:5|max:100',
]);

$password = Validator::make($request->all(), [
    'password' => 'required|min:5|max:100',
]);

if ($email->passes() && $password->passes())
{
    // Attempt Auth using email and password
}
elseif ($phone->passes() && $password->passes())
{
    // Attempt Auth using phone and password
}
else
{
    // Validation failed
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

schajee schajee Joined 11 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.