Created
September 24, 2021 20:44
-
-
Save luscas/d58eb585a8ce0dce6afb52ab4cf63d58 to your computer and use it in GitHub Desktop.
Renanzin
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; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
class AuthController extends Controller | |
{ | |
// Muda a rota pra AuthController@index ao invés de dashboard pra seguir o padrão REST (index, show, update, create, delete...) | |
public function index() | |
{ | |
if (Auth::check()) { | |
return view('admin.dashboard'); | |
} | |
return redirect()->route('admin.login'); | |
} | |
public function showLoginForm() | |
{ | |
return view('admin.login'); | |
} | |
public function login(Request $request) | |
{ | |
$credenciais = [ | |
'email' => $request->email, | |
'password' => $request->password | |
]; | |
if (Auth::attempt($credenciais)) { | |
return redirect()->route('admin'); | |
} | |
return redirect() | |
->back() | |
->withInput() | |
->withErrors(['Os dados informados não conferem']); | |
} | |
public function logout() | |
{ | |
Auth::logout(); | |
return redirect()->route('admin.login'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment