| Package Data | |
|---|---|
| Maintainer Username: | LucasRodriguesBR |
| Maintainer Contact: | lucas.opensource@gmail.com (Lucas Rodrigu) |
| Package Create Date: | 2017-07-19 |
| Package Last Update: | 2017-07-19 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-27 03:04:26 |
| Package Statistics | |
|---|---|
| Total Downloads: | 50 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 0 |
| Total Watchers: | 1 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
A simple helper for json response in laravel projects
composer require urameshibr/jsonresponse
The helper need 4 parameters:
status
http code
message
data (optional)
<?php
// Any controller
public function show($id)
{
$customer = $this->repository->showCustomerData($id);
return $customer-isEmpty()
? json_response(false, 404, "Customer not found")
: json_response(true, 200, "Customer info", $customer);
}
This will return a json:
{
"status": "true",
"code": 200,
"message": "Customer info",
"data": {
// customer data
}
}
or
{
"status": "false",
"code": 404,
"message": "Customer not found.",
"data": null
}
Note: * This package use the helper "response()" from Illuminate.
Note: * You can use 404 for "not found data" or 422. (or 666)