1<?php
2
3namespace App\Http\Controllers\Auth;
4
5use App\Http\Controllers\Controller;
6use App\Providers\RouteServiceProvider;
7use Illuminate\Foundation\Auth\AuthenticatesUsers;
8use Illuminate\Http\Request;
9use Illuminate\Validation\ValidationException;
10
11class LoginController extends Controller
12{
13 /*
14 |--------------------------------------------------------------------------
15 | Login Controller
16 |--------------------------------------------------------------------------
17 |
18 | This controller handles authenticating users for the application and
19 | redirecting them to your home screen. The controller uses a trait
20 | to conveniently provide its functionality to your applications.
21 |
22 */
23
24 use AuthenticatesUsers;
25
26 /**
27 * Where to redirect users after login.
28 *
29 * @var string
30 */
31 protected $redirectTo = RouteServiceProvider::HOME;
32
33 /**
34 * Create a new controller instance.
35 *
36 * @return void
37 */
38 public function __construct()
39 {
40 $this->middleware('guest')->except('logout');
41 }
42
43 /**
44 * Get the failed login response instance.
45 *
46 * @param \Illuminate\Http\Request $request
47 * @return \Symfony\Component\HttpFoundation\Response
48 *
49 * @throws \Illuminate\Validation\ValidationException
50 */
51 protected function sendFailedLoginResponse(Request $request)
52 {
53 throw ValidationException::withMessages([
54 'username' => [trans('auth.failed')],
55 ]);
56 }
57
58 /**
59 * Get the login username to be used by the controller.
60 *
61 * @return string
62 */
63 public function username()
64 {
65 $login = request()->input('username');
66
67 if(is_numeric($login)){
68 $field = 'phone';
69 } elseif (filter_var($login, FILTER_VALIDATE_EMAIL)) {
70 $field = 'email';
71 } else {
72 $field = 'username';
73 }
74
75 request()->merge([$field => $login]);
76
77 return $field;
78 }
79}
80
81