Last active
October 7, 2018 20:35
-
-
Save mostafa6765/b8be103af008c2d11a5a8031ac26574b to your computer and use it in GitHub Desktop.
This file contains 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\Admin; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
use Illuminate\Http\Request; | |
use Auth; | |
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'; | |
public function __construct() | |
{ | |
$this->middleware('guest:admin')->except('logout'); | |
} | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function login() | |
{ | |
return view('admin.auth.login'); | |
} | |
public function loginAdmin(Request $request) | |
{ | |
// Validate the form data | |
$this->validate($request, [ | |
'email' => 'required|email', | |
'password' => 'required|min:6' | |
]); | |
// Attempt to log the user in | |
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) { | |
// if successful, then redirect to their intended location | |
return redirect()->intended(route('admin.dashboard')); | |
} | |
// if unsuccessful, then redirect back to the login with the form data | |
return redirect()->back()->withInput($request->only('email', 'remember')); | |
} | |
public function logout() | |
{ | |
Auth::guard('admin')->logout(); | |
return redirect()->route('admin.auth.login'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment