PHP code example of fake-fakers / laravel-api-components
1. Go to this page and download the library: Download fake-fakers/laravel-api-components 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/ */
fake-fakers / laravel-api-components example snippets
use Brainex\ApiComponents\Exceptions\BaseHandler;
class Handler extends BaseHandler
{
// write your code here
}
/**
* A list of custom exception handlers
*
* @return array
*/
protected function getCustomHandlers(): array
{
return [
OAuthServerException::class => [$this, 'oauthServerJson']
];
}
/**
* Get JsonResponse for OAuthServerException exception
*
* @param OAuthServerException $exception
* @return JsonResponse
*/
protected function oauthServerJson(OAuthServerException $exception): JsonResponse
{
return \response()->json([
'message' => $exception->getErrorType(),
'data' => [
'description' => $exception->getMessage(),
'hint' => $exception->getHint()
]
], $exception->getHttpStatusCode(), $exception->getHttpHeaders());
}
declare(strict_types=1);
namespace App;
use Illuminate\Log\LogServiceProvider;
use Illuminate\Events\EventServiceProvider;
/**
* Class Application
* @package App
*
* Overriding original application to hook router
*/
class Application extends \Illuminate\Foundation\Application
{
/**
* Register all of the base service providers.
*
* @return void
*/
protected function registerBaseServiceProviders(): void
{
$this->register(new EventServiceProvider($this));
$this->register(new LogServiceProvider($this));
// hook responses to make them JSON_UNESCAPED_UNICODE
$this->register(new \Brainex\ApiComponents\Routing\RoutingServiceProvider($this));
}
}
$app = new \App\Application(
realpath(__DIR__.'/../')
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.