urameshibr / jsonresponse by LucasRodriguesBR

Helper for json response in laravel
44
0
1
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: 2019-12-11 03:17:52
Package Statistics
Total Downloads: 44
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

jsonresponse

A simple helper for json response in laravel projects

how to install

composer require urameshibr/jsonresponse

How to use

The helper need 4 parameters:

  • status

  • http code

  • message

  • data (optional)

Example

<?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)