PHP code example of milito / response-generator

1. Go to this page and download the library: Download milito/response-generator 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/ */

    

milito / response-generator example snippets




return [
    //....
    
    "providers" => [
        //...
                \Milito\ResponseGenerator\Providers\MilitoResponseGeneratorServiceProvider::class,
        //...
    ]
];


use Illuminate\Support\Facades\Route;
use Milito\ResponseGenerator\Facades\MilitoResponseGenerator;

Route::get('/', function () {
    return MilitoResponseGenerator::success()
            ->succeeded() // Sets the `Http Status code` field of response to `HTTP_OK` (200).
            ->message("Success response message") // Sets the `message` field of response.
            ->data([
                "body" => "Success response body"
            ]) // Sets the `data` field of response.
            ->send(); // Generates the response as a `json` response.
});


use Illuminate\Support\Facades\Route;
use Milito\ResponseGenerator\Facades\MilitoResponseGenerator;

Route::get('/', function () {
    return MilitoResponseGenerator::failed()
            ->code(\Illuminate\Http\Response::HTTP_INTERNAL_SERVER_ERROR) // Sets the `Http Status code` field of response to `SERVER_ERROR` (500).
            ->message("Error Response message") // Sets the `message` field of response.
            ->errors(["Yeah this is error"]) // Sets the `error` & the `errors` fields of response.
            ->send(); // Generates the response as a `json` response.
});
sh
php artisan vendor:publish --tag=milito-response-config