Skip to content

Instantly share code, notes, and snippets.

@mahammad
Created November 21, 2021 21:23
Show Gist options
  • Save mahammad/655320cb22d82f01a852745e83dfd4a6 to your computer and use it in GitHub Desktop.
Save mahammad/655320cb22d82f01a852745e83dfd4a6 to your computer and use it in GitHub Desktop.
How to create laravel sanctum ability
<?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