PHPackages                             codebot/laravel-response-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. codebot/laravel-response-builder

ActiveLibrary[API Development](/categories/api)

codebot/laravel-response-builder
================================

Simple package for Laravel framework to standardize the structure of JSON responses.

1.1.5(3y ago)242.0k—6.9%[2 PRs](https://github.com/hakobyansen/laravel-response-builder/pulls)MITPHPPHP ^8.0

Since Sep 15Pushed 2y agoCompare

[ Source](https://github.com/hakobyansen/laravel-response-builder)[ Packagist](https://packagist.org/packages/codebot/laravel-response-builder)[ RSS](/packages/codebot-laravel-response-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (25)Used By (0)

About
-----

[](#about)

Package `codebot/laravel-response-builder` is a simple package for Laravel framework to standardize the structure of JSON responses.

You will find this package helpful if you need your responses to look like this:

```
{
  "status": true,
  "message": "You got that!",
  "data" : {
    "name": "James Joesph Bulger",
    "profession": "criminal"
  },
  "errors": []
}
```

or

```
{
  "status": false,
  "message": "Something went wrong...",
  "data" : [],
  "errors": {
    "email": [
      "The email field is required."
    ]
  }
}
```

Installation
------------

[](#installation)

```
composer require codebot/laravel-response-builder:^1

```

**For Laravel 5.4 and versions below add `\Rb\Core\RbServiceProvider::class` to providers in config/app.php file.**

Next run the command below in your console:

```
php artisan vendor:publish --tag=laravel-response-builder

```

Requests
--------

[](#requests)

Once you published vendor, you should see `App\Http\Requests\Rb\RbRequest class`. This will be base class for laravel-response-builder's requests.
To generate a request that extends RbRequest, run:

```
php artisan make:rbrequest YourNewRequest

```

If you are using Laravel's Validator class, you can use `Rb\Core\RbValidator` to standardize the structure of failed response.

```
use \Rb\Core\RbValidator;
use Illuminate\Support\Facades\Validator;

$validator = new Validator($data, $rules); // assuming you have a $validator instance

RbValidator::validate($validator); // throws HttpResponseException or returns boolean true
```

RbValidator::validate() method checks if the validation fails and throws Illuminate\\Http\\Exceptions\\HttpResponseException with the standardized json response structure.

### Usage

[](#usage)

```
use \Rb\Core\Response;
use \Rb\Core\HttpStatusCode;

$response = new Response();

$response->setStatusCode(HttpStatusCode::OK); // required. If code is 2XX then Response::status field will be "true", otherwise "false"

$response->setMessage('Some inspiring message.'); // null will be returned if no message set

$response->setData($data); // null will be returned if no data set

$response->setErrors($errors); // null will be returned if no error set

$response->getArray(); // will return an array of data set

$response->getResponse(); // will return a json response using Laravel's response() helper
```

All setters are fluent, so example above could be written like:

```
use \Rb\Core\Response;
use \Rb\Core\HttpStatusCode;

$response = new Response();

$response->setStatusCode(HttpStatusCode::OK)
    ->setMessage('Some inspiring message.');
    // ...
```

Package contains HttpStatusCode class with http status codes defined.

```
use \Rb\Core\HttpStatusCode;

HttpStatusCode::OK; // returns status code 200 (integer)

HttpStatusCode::getMessageByCode(HttpStatusCode::NOT_FOUND); // returns string "Not Found"

HttpStatusCode::getCodeWithMessage(HttpStatusCode::CREATED); // returns string - code and message, e.g. "201 Created"
```

#### The Facade

[](#the-facade)

The package contains a facade class in case if you don't want to interact with all of these setters.

```
use \Rb\Facade\Response;
use \Rb\Core\HttpStatusCode;

return Response::success(
   data: $data,
   message: 'Created List of users.'
);

return Response::error(
   errors: $errors,
   message: 'Invalid input.',
   statusCode: HttpStatusCode::UNPROCESSABLE_ENTITY
);

// Without $data (the $errors parameter is also optional)
return Response::success(message: 'User deleted.');
```

`$data` and `$errors` variables are arrays and are optional.

Configuration
-------------

[](#configuration)

Once you have vendor published, you should see `config/response_builder.php` file.

**request\_path** - Generated request classes will be stored in specified directory.

**request\_namespace** - Namespace for generated request class.

**is\_authorize** - Default value of Request's authorize() method.

**messages** - Contains messages for Response's "message" field.

*messages.failed\_validation* - Default message for response that failed the validation.

Fields
------

[](#fields)

`status` - boolean (Not Nullable)
`status_code` - integer (Not Nullable)
`message` - string (Nullable)
`data` - array (Not Nullable, can be empty)
`errors` - array (Not Nullable, can be empty)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~88 days

Total

20

Last Release

1134d ago

Major Versions

0.3.1 → 1.02021-01-25

PHP version history (2 changes)0.0.8PHP ^7.1

1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/46efdc41146809a879b858eb0fa5bbf94c34f931866a1237e7467eeaa5f752e1?d=identicon)[sen.hakobyan](/maintainers/sen.hakobyan)

---

Top Contributors

[![hakobyansen](https://avatars.githubusercontent.com/u/43189667?v=4)](https://github.com/hakobyansen "hakobyansen (194 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

json-responseslaravellaravel-frameworklaravel-response-builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codebot-laravel-response-builder/health.svg)

```
[![Health](https://phpackages.com/badges/codebot-laravel-response-builder/health.svg)](https://phpackages.com/packages/codebot-laravel-response-builder)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
