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';
}
}
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
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community