laravel auth username instead of email code example
Example 1: laravel using username instead of email
All we need is add a method in app/Http/Controllers/Auth/LoginController.php:
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return 'username';
}
Example 2: laravel 6 use username instead of id
// using User->username instead of id on url:
public function show($user)
{
// where<YourAtributeName>($param)->firstOrFail()
$user = User::whereUsername($user)->firstOrFail();
return view('users.show', ['user'=>$user]);
}