<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Session;

class AuthMiddleware
{
    public function handle($request, Closure $next)
    {
        // Check for authentication in session
        if (!Session::has('RegNo')) {
            return redirect()->route('login')->withErrors(['message' => 'Please log in to access this page.']);
        }

        return $next($request);
    }
}
