<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; // Wajib aya ieu!

class AdminMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        // Mun geus login jeung role-na admin, lanjut
        if (Auth::check() && Auth::user()->role == 'admin') {
            return $next($request);
        }

        // Mun lain admin, balikkeun ka home
        return redirect('/')->with('error', 'Punten mang, husus admin!');
    }
}