PHP code example of hatchyu / laravel-api-exceptions
1. Go to this page and download the library: Download hatchyu/laravel-api-exceptions 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/ */
hatchyu / laravel-api-exceptions example snippets
use Hatchyu\ApiExceptions\Http\BadRequestException;
// Returns a 400 JSON response:
// { "error": { "message": "Invalid payload." } }
throw new BadRequestException('Invalid payload.');
use Hatchyu\ApiExceptions\General\FileTooLargeException;
use Hatchyu\ApiExceptions\General\FileUploadException;
use Hatchyu\ApiExceptions\General\UnsupportedFileTypeException;
use Hatchyu\ApiExceptions\Model\ModelNotFoundException;
use Hatchyu\ApiExceptions\Model\ModelCreateException;
use Hatchyu\ApiExceptions\Model\ModelUpdateException;
use Hatchyu\ApiExceptions\Model\ModelDeleteException;
throw FileTooLargeException::for('invoice.pdf');
throw FileUploadException::for('invoice.pdf');
throw UnsupportedFileTypeException::forFile('invoice.pdf', 'application/pdf');
throw ModelNotFoundException::forModel(Customer::class, 3);
throw ModelCreateException::forModel(Customer::class, 'Email already exists');
throw ModelUpdateException::forModel($customer);
throw ModelDeleteException::forModel($customer, 'Customer has active orders');
// Non-"id" primary keys are resolved automatically from the model instance.
// Example output: "Failed to update Order (order_id: ORD-1001)."
throw ModelUpdateException::forModel($order);