Created
May 14, 2021 14:43
-
-
Save ninjaparade/d367c4cb9e9c53d25d30a01db01ad799 to your computer and use it in GitHub Desktop.
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; | |
class SanctumAbilities | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, ...$abilities) | |
{ | |
foreach ($abilities as $ability) { | |
if (!$request->user()->tokenCan($ability)) { | |
abort(404); | |
} | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment