<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class CheckRole
{
    public function handle(Request $request, Closure $next, $role)
    {
        if (!$request->user() || $request->user()->role !== $role) {
            if ($role === 'admin') {
                return redirect()->route('customer.dashboard');
            } else {
                return redirect()->route('admin.dashboard');
            }
        }

        return $next($request);
    }
} 