File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1111use Symfony \Component \HttpKernel \Exception \MethodNotAllowedHttpException ;
1212use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1313use Symfony \Component \HttpKernel \Exception \UnauthorizedHttpException ;
14+ use Illuminate \Auth \Access \AuthorizationException ;
1415
1516class Handler extends ExceptionHandler
1617{
@@ -52,9 +53,14 @@ public function report(Exception $exception)
5253 */
5354 public function render ($ request , Exception $ exception )
5455 {
56+ //dd($exception);
5557 if (strpos ($ request ->url (), '/api/ ' ) !== false ) {
5658 \Log::debug ('API Request Exception - ' .$ request ->url ().' - ' .$ exception ->getMessage ().(!empty ($ request ->all ()) ? ' - ' .json_encode ($ request ->except (['password ' ])) : '' ));
5759
60+ if ($ exception instanceof AuthorizationException) {
61+ return $ this ->setStatusCode (403 )->respondWithError ($ exception ->getMessage ());
62+ }
63+
5864 if ($ exception instanceof MethodNotAllowedHttpException) {
5965 return $ this ->setStatusCode (403 )->respondWithError ('Please check HTTP Request Method. - MethodNotAllowedHttpException ' );
6066 }
Original file line number Diff line number Diff line change 22
33namespace App \Http \Controllers \Api \V1 ;
44
5- use App \Http \Resources \UserResource ;
5+ use Validator ;
6+ use Illuminate \Http \Request ;
67use App \Models \Access \User \User ;
8+ use App \Http \Resources \UserResource ;
79use App \Repositories \Backend \Access \User \UserRepository ;
8- use Illuminate \Http \Request ;
9- use Validator ;
10+ use App \Http \Requests \Backend \Access \User \ManageUserRequest ;
1011
1112class UsersController extends APIController
1213{
@@ -29,7 +30,7 @@ public function __construct(UserRepository $repository)
2930 *
3031 * @return \Illuminate\Http\JsonResponse
3132 */
32- public function index (Request $ request )
33+ public function index (ManageUserRequest $ request )
3334 {
3435 $ limit = $ request ->get ('paginate ' ) ? $ request ->get ('paginate ' ) : 25 ;
3536
Original file line number Diff line number Diff line change 33namespace App \Http \Requests ;
44
55use Illuminate \Foundation \Http \FormRequest ;
6+ use Illuminate \Auth \Access \AuthorizationException ;
67
78/**
89 * Class Request.
@@ -25,4 +26,9 @@ public function forbiddenResponse()
2526
2627 return redirect ()->back ()->withErrors ($ this ->error );
2728 }
29+
30+ protected function failedAuthorization ()
31+ {
32+ throw new AuthorizationException ('This action is unauthorized. ' );
33+ }
2834}
You can’t perform that action at this time.
0 commit comments