PHP code example of f9webltd / laravel-api-response-helpers

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

    

f9webltd / laravel-api-response-helpers example snippets




namespace App\Http\Api\Controllers;

use F9Web\ApiResponseHelpers;
use Illuminate\Http\JsonResponse;

class OrdersController
{
    use ApiResponseHelpers;

    public function index(): JsonResponse
    {
        return $this->respondWithSuccess();
    }
}

$users = collect([10, 20, 30, 40]);

return $this->setDefaultSuccessResponse([])->respondWithSuccess($users);

public function __construct()
{
    $this->setDefaultSuccessResponse([]);
}

...

$users = collect([10, 20, 30, 40]);

return $this->respondWithSuccess($users);

$users = collect([10, 20, 30, 40]);

return $this->respondWithSuccess($users);

$invoices = Invoice::pending()->get();

return $this->respondWithSuccess($invoices);

$resource = PostResource::make($post);

return $this->respondCreated($resource);