Middleware
Create Middleware
<?php
namespace App\Middleware;
class AuthMiddleware
{
public function handle($request, $next)
{
// Check if the user is logged in
if (!isset($_SESSION['user'])) {
echo "Unauthorized access!";
exit;
}
// Proceed to the next middleware or controller
return $next($request);
}
}Using Middleware in Route
More Example
Last updated
Was this helpful?