hamid-re3a/response-transformer

Simple transfomer to return Json responses.

dev-master 2023-12-31 06:51 UTC

This package is auto-updated.

Last update: 2025-08-29 03:00:32 UTC


README

The main purpose of this package is to return the response in the desired way as the frontend development team requested.

Setup:

This is a private package. So, the installation process is completely different. For this purpose, we recorded 2 videos which you can watch to learn how to install this package.

  1. Installation
  2. After installation, register the package service provider in app.php file like other packages.
    • \ResponseTransformerServiceProvider::class
  3. Register the package façade alias in app.php file:
    • 'RTransformer' => ResponseTransformer\Facades\API::class
  4. Finally you can publish the config file:
    • php artisan vendor:publish --tag=transformer-response

Usage:

You can using this package as façade as well as a helper function.

01. Helper Function:

public function index()
{
    $user = User::first();
    return api()->response(200, 'The very first user in the database', $user);
}

02. Facade:

use RTransformer;
public function index()
{
    $user = User::first();
    return RTransformer->response(200, 'The very first user in the database', $user);
}

Response

{
      "status": 200,
      "message": "The very first user in the database",
      "data": [
           {"name": "Hamid Noruzi"}
       ]
}