LaravelPackages.net
Acme Inc.
Toggle sidebar
urameshibr/jsonresponse

Helper for json response in laravel

50
0
1.1
About urameshibr/jsonresponse

urameshibr/jsonresponse is a Laravel package for helper for json response in laravel. It currently has 0 GitHub stars and 50 downloads on Packagist (latest version 1.1). Install it with composer require urameshibr/jsonresponse. Discover more Laravel packages by urameshibr or browse all Laravel packages to compare alternatives.

Last updated

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)

Comments