|string> */ public function rules(): array { return [ 'username' => 'required', 'password' => 'required' ]; } /** * Get the needed authorization credentials from the request. * * @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function getCredentials() { // The form field for providing username or password // have name of "username", however, in order to support // logging users in with both (username and email) // we have to check if user has entered one or another $username = $this->get('username'); if ($this->isEmail($username)) { return [ 'email' => $username, 'password' => $this->get('password') ]; } return $this->only('username', 'password'); } /** * Validate if provided parameter is valid email. * * @param $param * @return bool * @throws \Illuminate\Contracts\Container\BindingResolutionException */ private function isEmail($param) { $factory = $this->container->make(ValidationFactory::class); return ! $factory->make( ['username' => $param], ['username' => 'email'] )->fails(); } }