project-ta/.history/bootstrap/app_20260331095413.php

41 lines
940 B
PHP

<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class RoleMiddleware
{
public function handle(Request $request, Closure $next, $role)
{
if (!Auth::check()) {
return redirect('/login');
}
if (Auth::user()->role != $role) {
abort(403, 'AKSES DITOLAK');
}
return $next($request);
}
}
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();