PHP code example of igorsgm / laravel-api-responses

1. Go to this page and download the library: Download igorsgm/laravel-api-responses 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/ */

    

igorsgm / laravel-api-responses example snippets

bash
php artisan vendor:publish --provider="Igorsgm\LaravelApiResponses\LaravelApiResponsesServiceProvider"
 php
class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        // ...
        'api' => [
            \Igorsgm\LaravelApiResponses\Http\Middleware\ApiResponse::class,
            // ...
        ],
    ];
    
    // ...
}
 php
response()->success($data, $message) // ($data = [], $message = '', $status = 200, $headers = [])
response()->successMessage($message) // ($message = '', $status = 200, $headers = [])
response()->error($errors) // ($errors = [], $message = '', $status = 500, $headers = [])
response()->errorMessage($message) // ($message = '', $status = 500, $headers = [])
response()->exceptionError($exception) // ($exception, $message = '', $status = 0, $headers = [])