urameshibr / jsonresponse by LucasRodriguesBR

Helper for json response in laravel
49
0
2
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: 2024-04-26 03:11:15
Package Statistics
Total Downloads: 49
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
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)