1. Go to this page and download the library: Download dragon-code/api-response 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/ */
use DragonCode\ApiResponse\Services\Response;
Response::allowWith();
$e = new Exception('Foo', 0);
return api_response($e);
use DragonCode\ApiResponse\Services\Response;
Response::withoutWith();
$e = new Exception('Foo', 0);
return api_response($e);
class FooException extends \Exception
{
public function __construct()
{
parent::__construct('Foo', 405);
}
}
class BarException extends \Exception
{
public function __construct()
{
parent::__construct('Bar');
}
}
$foo = new FooException();
$bar = new BarException();
namespace App\Exceptions;
use DragonCode\ApiResponse\Exceptions\Laravel\Nine\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
//
}
namespace App\Exceptions;
// use DragonCode\ApiResponse\Exceptions\Laravel\Nine\Handler as ExceptionHandler;
use DragonCode\ApiResponse\Exceptions\Laravel\Nine\ApiHandler as ExceptionHandler;
// use DragonCode\ApiResponse\Exceptions\Laravel\Eight\Handler as ExceptionHandler;
// use DragonCode\ApiResponse\Exceptions\Laravel\Eight\ApiHandler as ExceptionHandler;
// use DragonCode\ApiResponse\Exceptions\Laravel\Seven\Handler as ExceptionHandler;
// use DragonCode\ApiResponse\Exceptions\Laravel\Seven\ApiHandler as ExceptionHandler;
class Handler extends ExceptionHandler
{
//
}
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin \Tests\Fixtures\Laravel\Model */
final class Resource extends JsonResource
{
public function toArray($request)
{
return [
'foo' => $this->foo,
'bar' => $this->bar,
];
}
public function with($request)
{
return ['baz' => 'Baz'];
}
}