Search
 
SCRIPT & CODE EXAMPLE
 

PHP

login with email or phone number laravel

    public function username()
    {
        $login = request()->input('username');

        if(is_numeric($login)){
            $field = 'phone';
        } elseif (filter_var($login, FILTER_VALIDATE_EMAIL)) {
            $field = 'email';
        } else {
            $field = 'username';
        }

        return $field;
    }
Comment

laravel auth login with phone or email

<?php

namespace AppHttpControllersAuth;

use AppHttpControllersController;
use AppProvidersRouteServiceProvider;
use IlluminateFoundationAuthAuthenticatesUsers;
use IlluminateHttpRequest;
use IlluminateValidationValidationException;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Get the failed login response instance.
     *
     * @param  IlluminateHttpRequest  $request
     * @return SymfonyComponentHttpFoundationResponse
     *
     * @throws IlluminateValidationValidationException
     */
    protected function sendFailedLoginResponse(Request $request)
    {
        throw ValidationException::withMessages([
            'username' => [trans('auth.failed')],
        ]);
    }

    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        $login = request()->input('username');

        if(is_numeric($login)){
            $field = 'phone';
        } elseif (filter_var($login, FILTER_VALIDATE_EMAIL)) {
            $field = 'email';
        } else {
            $field = 'username';
        }

        request()->merge([$field => $login]);

        return $field;
    }
}

Comment

PREVIOUS NEXT
Code Example
Php :: what is scalar data type in php 
Php :: store emoji in php 
Php :: php add property to object 
Php :: pluck array in laravel 
Php :: php remove path from string url 
Php :: php regex string contains coringa 
Php :: php datetime set timezone 
Php :: how to validate video laravel 
Php :: <a href="<?php echo base_url(); ?"somelink</a 
Php :: send html email laravel 
Php :: what is the hashmap like in php 
Php :: echo ternary php 
Php :: for loop in laravel 
Php :: query php 
Php :: php How do you remove an array element in a foreach loop? 
Php :: range in php 
Php :: php extensions for apache2 
Php :: how to get product id by sku in woocommerce 
Php :: php global variable function 
Php :: changing created_at to short date time 
Php :: tinyinteger laravel +size 
Php :: contact form 7 remove p 
Php :: php check if post file is empty 
Php :: multiple logical condition in laravel query 
Php :: limited text show in laravel 
Php :: wp post featured image not showing admin 
Php :: laravel create project with auth 2021 
Php :: php remove space from string 
Php :: unique array 
Php :: how to run multiple seeder at a time in laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =