PHP code example of antarctica / laravel-json-exception-formatter

1. Go to this page and download the library: Download antarctica/laravel-json-exception-formatter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antarctica / laravel-json-exception-formatter example snippets


'providers' => array(

	'Antarctica\JsonExceptionFormatter\JsonExceptionFormatterServiceProvider',
	
),



use Antarctica\LaravelBaseExceptions\Exception\HttpException;

class AuthenticationException extends HttpException {

    protected $statusCode = 401;

    protected $kind = 'authentication_failure';

    protected $details = [
        "authentication_error" => [
            "Ensure your credentials are correct and that your user account is still active, or contact the maintainer of this API for assistance."
        ]
    ];
}
json
{
    "errors": [
        {
            "details": {
                "authentication_error": [
                    "Ensure your credentials are correct and that your user account is still active, or contact the maintainer of this API for assistance."
                ]
            },
            "exception": "Antarctica\\LaravelTokenAuth\\Exception\\Auth\\AuthenticationException",
            "file": "/app/vendor/antarctica/laravel-token-auth/src/Antarctica/LaravelTokenAuth/Service/Token/TokenServiceJwtAuth.php",
            "kind": "authentication_failure",
            "line": 88,
            "stack_trace": [
                {
                    "file": "/app/vendor/antarctica/laravel-token-auth/src/Antarctica/LaravelTokenAuth/Service/TokenUser/TokenUserService.php",
                    "line": 91,
                    "function": "authOnce",
                    "class": "Antarctica\\LaravelTokenAuth\\Service\\Token\\TokenServiceJwtAuth",
                    "type": "->",
                    "args": [
                        {
                            "username": "xxx",
                            "password": "xxx"
                        }
                    ]
                },
                ...
                {
                    "file": "/app/public/index.php",
                    "line": 49,
                    "function": "run",
                    "class": "Illuminate\\Foundation\\Application",
                    "type": "->",
                    "args": []
                }
            ]
        }
    ]
}