Created
November 21, 2021 21:23
-
-
Save mahammad/655320cb22d82f01a852745e83dfd4a6 to your computer and use it in GitHub Desktop.
How to create laravel sanctum ability
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 Illuminate\Http\Request; | |
class SanctumAbilityCheck | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle(Request $request, Closure $next, $ability) | |
{ | |
if (!$request->user()->tokenCan($ability)) { | |
abort(400, 'Access denied'); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment