Skip to content

Instantly share code, notes, and snippets.

@luscas
Created September 24, 2021 20:44
Show Gist options
  • Save luscas/d58eb585a8ce0dce6afb52ab4cf63d58 to your computer and use it in GitHub Desktop.
Save luscas/d58eb585a8ce0dce6afb52ab4cf63d58 to your computer and use it in GitHub Desktop.
Renanzin
<?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