PHP code example of jongoly / api-standardizer

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

    

jongoly / api-standardizer example snippets


return [
    'keys' => [
        'success' => 'success',
        'data'    => 'data',
        'message' => 'message',
        'errors'  => 'errors',
        'pagination' => 'pagination'
    ],
];

namespace App\Http\Controller;
use App\Models\User;
use Jongoly\ApiStandardizer\Concerns\ApiResponse;

class UserController extends Controller
{
    use ApiResponse;

    public function index()
    {
        \$users = User::paginate(10);

        // Return a standardized success response
        return this->success(users, 'Users fetched successfully.', 200);
    }
}

return this->success(data, 'Users fetched successfully.');

return $this->error('Validation Failed.', 422, [
    'The Email must be valid.'
]);
bash 
php artisan vendor:publish --tag="api-standardizer-config"