Skip to content

Commit 77beaad

Browse files
committed
auth can macro added
1 parent 799b860 commit 77beaad

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Providers/MacroServiceProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Fintech\Core\Providers;
44

5-
use Exception;
65
use Fintech\Core\Enums\RequestPlatform;
76
use Illuminate\Database\Eloquent\ModelNotFoundException;
87
use Illuminate\Http\Client\ConnectionException;
98
use Illuminate\Http\JsonResponse;
109
use Illuminate\Http\Request;
10+
use Illuminate\Support\Facades\Auth;
1111
use Illuminate\Support\Facades\Http;
1212
use Illuminate\Support\Facades\Response as ResponseFacade;
1313
use Illuminate\Support\ServiceProvider;
@@ -219,5 +219,15 @@ public function boot()
219219
ResponseFacade::macro('overflow', function ($data, array $headers = []) {
220220
return response()->json(response_format($data, Response::HTTP_TOO_MANY_REQUESTS), Response::HTTP_TOO_MANY_REQUESTS, $headers);
221221
});
222+
223+
/**
224+
* Alias of Auth::user()->can() method
225+
*
226+
* @param mixed $permissions
227+
* @return bool
228+
*/
229+
Auth::macro('can', function (...$permissions) {
230+
return Auth::guard('api')->user()?->can($permissions) ?? false;
231+
});
222232
}
223233
}

0 commit comments

Comments
 (0)