PHP code example of curly-deni / laravel-api-concern
1. Go to this page and download the library: Download curly-deni/laravel-api-concern 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/ */
curly-deni / laravel-api-concern example snippets
use Aesis\ApiConcern\Concerns\HasApiResponses;
use Illuminate\Routing\Controller;
class UserController extends Controller
{
use HasApiResponses;
public function store()
{
return $this->created(['id' => 1], ['request_id' => 'abc']);
}
}
use Aesis\ApiConcern\Http\ApiExceptionRenderer;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Http\Request;
use Throwable;
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->render(function (Throwable $exception, Request $request) {
if (! $request->is('api/v1/*')) {
return null;
}
return app(ApiExceptionRenderer::class)->render($exception);
});
})
throw new ApiException('account_locked', 'This account is locked.', 423, ['retry_after' => 60]);