feat: 統一全系統頁面標題樣式、優化側邊欄與實作角色成員查看功能
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Spatie\Permission\Exceptions\UnauthorizedException;
|
||||
use Inertia\Inertia;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
@@ -14,7 +17,25 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
$middleware->web(append: [
|
||||
\App\Http\Middleware\HandleInertiaRequests::class,
|
||||
]);
|
||||
|
||||
// 註冊 Spatie Permission 中間件別名
|
||||
$middleware->alias([
|
||||
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
|
||||
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
|
||||
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
|
||||
]);
|
||||
})
|
||||
->withExceptions(function (Exceptions $exceptions): void {
|
||||
//
|
||||
// 處理 Spatie Permission 的 UnauthorizedException
|
||||
$exceptions->render(function (UnauthorizedException $e) {
|
||||
return Inertia::render('Error/403')->toResponse(request())->setStatusCode(403);
|
||||
});
|
||||
|
||||
// 處理一般的 403 HttpException
|
||||
$exceptions->render(function (HttpException $e) {
|
||||
if ($e->getStatusCode() === 403) {
|
||||
return Inertia::render('Error/403')->toResponse(request())->setStatusCode(403);
|
||||
}
|
||||
});
|
||||
})->create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user