Created
June 29, 2020 07:11
-
-
Save blood72/7e456f5445a789fa7167e0bd79de3f8e to your computer and use it in GitHub Desktop.
404 middleware version of spatie/laravel-permission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Spatie\Permission\Middlewares\PermissionMiddleware as Middleware; | |
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
class Permission404Middleware extends Middleware | |
{ | |
/** | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param mixed $permission | |
* @return mixed | |
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | |
*/ | |
public function handle($request, Closure $next, $permission) | |
{ | |
try { | |
return parent::handle($request, $next, $permission); | |
} catch (\Spatie\Permission\Exceptions\UnauthorizedException $exception) { | |
throw new NotFoundHttpException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
in app/Http/Kernel.php
in routes/web.php