Last active
October 17, 2018 07:52
-
-
Save faryar76/25e09c96208b147188dbe14f7349798d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
use Illuminate\Http\Request; | |
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 = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest')->except('logout'); | |
} | |
/** | |
* override of trait | |
* get which culomn used for login / email or username | |
* in blade input name is "name" | |
* @return string | |
*/ | |
public function username() | |
{ | |
return 'name'; | |
} | |
/** | |
* override of trait | |
* Get the needed authorization credentials from the request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return array | |
*/ | |
protected function credentials(Request $request) | |
{ | |
return [ | |
$this->getLoginType() => $request->name, | |
'password' => $request->password | |
]; | |
// return $request->only($this->username(), 'password'); | |
} | |
public function getLoginType() | |
{ | |
if(filter_var(request()->name,FILTER_VALIDATE_EMAIL)) | |
{ | |
return 'email'; | |
} | |
return 'name'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment