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/ */
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.