Untitled
unknown
plain_text
a year ago
851 B
5
Indexable
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
public function index()
{
if (Auth::check()) {
return to_route($this->getRoleRoute('index'));
}
return view("login");
}
public function authenticate(Request $request)
{
$credentials = $request->only(['username', 'password']);
if (Auth::attempt($credentials)) {
$user = Auth::user();
$role = strtolower($user->role->name);
$redirect_route = $this->getRoleRoute('index');
return redirect()->route($redirect_route)->with('status', 'Login Berhasil!');
}
return back()->withErrors(['username' => 'Invalid credentials']);
}
}Editor is loading...
Leave a Comment