Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
851 B
1
Indexable
Never
<?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']);
    }
}
Leave a Comment