PHPackages                             nnjeim/respond - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nnjeim/respond

ActiveLaravel-package[Utility &amp; Helpers](/categories/utility)

nnjeim/respond
==============

Laravel response helpers

1.2.1(4y ago)5411MITPHPPHP &gt;=7.4

Since Sep 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nnjeim/respond)[ Packagist](https://packagist.org/packages/nnjeim/respond)[ Docs](https://github.com/nnjeim/respond.git)[ RSS](/packages/nnjeim-respond/feed)WikiDiscussions master Synced 1mo ago

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

[![](https://camo.githubusercontent.com/00febf8cd7a1fb21c09c3392694c065f864890c18fd816bae46060d9d64fb59f/68747470733a2f2f65752e75692d617661746172732e636f6d2f6170692f3f6e616d653d4e616a6d2b4e6a65696d3f73697a653d313030)](https://camo.githubusercontent.com/00febf8cd7a1fb21c09c3392694c065f864890c18fd816bae46060d9d64fb59f/68747470733a2f2f65752e75692d617661746172732e636f6d2f6170692f3f6e616d653d4e616a6d2b4e6a65696d3f73697a653d313030)

A Laravel response helper methods. The package `respond` provides a fluent syntax to form array or json responses.
In its configuration file, it allows the addition of custom methods.

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

[](#installation)

You can install the package via composer:

```
composer require nnjeim/respond

```

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

[](#configuration)

```
php artisan vendor:publish --provider="Nnjeim\Respond\RespondServiceProvider"

```

The `respond.php` config file allows:

- The presetting of the response format array/json.
- The possibility to edit the response parameters.
- The possibility to add custom methods.

Usage
-----

[](#usage)

##### Respond Facade

[](#respond-facade)

```
use Nnjeim\Fetch\Fetch;
use Nnjeim\Respond\Respond;

['response' => $response, 'status' => $status] = Fetch::setBaseUri('https://someapi.com/')->get('countries');

	if ($status === 200 && $response->success) {

		return Respond::toJson()
			->setMessage('countries')
			->setData($response->data)
			->withSuccess();
	}

	abort(400);

```

##### RespondHelper Instantiation

[](#respondhelper-instantiation)

```
use Nnjeim\Respond\RespondHelper;

private RespondHelper $respond;
private array $data;
private bool $success;

public function __construct(RespondHelper $respond)
{
	$this->respond = $respond;
}
.
.
.
$respond = $this
		->respond
		->toJson()
		->setMessage('countries')
		->setData($data);

if ($this->success)
{
	return $respond->withSuccess()
}

return $respond->withErrors();

```

Methods
-------

[](#methods)

##### Set the status code

[](#set-the-status-code)

```
Sets the response status code

@return $this       setStatusCode(int $statusCode)

```

##### Set the message

[](#set-the-message)

```
Sets the response title message

@return $this       setMessage(string $message)

```

##### Set the meta data

[](#set-the-meta-data)

```
Sets the response meta data. The meta data will be merged with the response data array.

@return $this       setMeta(array $meta)

```

##### Set the data

[](#set-the-data)

```
Sets the response data array.

@return $this       setData(array $data)

```

##### Set the errors

[](#set-the-errors)

```
Sets the response errors.

@return $this       setErrors(array $errors)

```

##### respond in Json format

[](#respond-in-json-format)

```
returns an instance of Illuminate\Http\JsonResponse

this method overwrites the config `toJson` set value.

@return $this       toJson()

```

##### Respond with success

[](#respond-with-success)

```
On success response. The default response status code is 200.

@return array|JsonResponse       withSuccess()

```

##### Respond with created

[](#respond-with-created)

```
On created response. The default response status code is 201.

@return array|JsonResponse       withCreated()

```

##### Respond with accepted

[](#respond-with-accepted)

```
On accepted response. The default response status code is 202.

@return array|JsonResponse       withAccepted()

```

##### Respond with no content

[](#respond-with-no-content)

```
On success response with no results found. The default status code is 204

@return array|JsonResponse       withNoContent()

```

##### Respond with errors

[](#respond-with-errors)

```
On error response. The default response status code is 422.

@return array|JsonResponse       withErrors(?array $errors = null)

```

##### Respond with server error

[](#respond-with-server-error)

```
On server error response. The default response status code is 500.

@return array|JsonResponse       withServerError()

```

##### Respond with not found

[](#respond-with-not-found)

```
Record not found error. The default response status code is 404.

@return array|JsonResponse       withNotFound()

```

##### Respond with not authenticated

[](#respond-with-not-authenticated)

```
Not authenticated reponse. The default response status code is 401.

@return array|JsonResponse       withNotAuthenticated()

```

##### Respond with not authorized

[](#respond-with-not-authorized)

```
Not authorized reponse. The default response status code is 403.

@return array|JsonResponse       withNotAuthorized()

```

Respond
-------

[](#respond)

```
@return array|JsonResponse

	[
		'response' => [
			'success' => true,
			'message' => 'message',
			'data' => [],
			'errors' => [],
		],
		'status' => 200,
	];

```

Custom methods
--------------

[](#custom-methods)

In the `respond.php` config file, in the responses array add an array entry where the key is name of the method in lower case and the value contains the desired success, message and status params.

```
//example
'methodnotallowed' => [
    'success' => false,
    'message' => 'the method not allowed!',
    'status' => Response::HTTP_METHOD_NOT_ALLOWED,
],

```

#### Usage

[](#usage-1)

`Respond::withMethodNotAllowed();`

Testing
-------

[](#testing)

The helpers and methods are tested with 99% coverage.
To run the tests.

```
composer install
composer test
```

To run the coverage test.

```
composer test-coverage
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

1700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c7c0bbf68a5085c71eb582298250ac2ffe5b4a971bd4fda304a1a6e3ec3bd02?d=identicon)[nnjeim](/maintainers/nnjeim)

---

Top Contributors

[![nnjeim](https://avatars.githubusercontent.com/u/78922079?v=4)](https://github.com/nnjeim "nnjeim (6 commits)")

---

Tags

json-apilaravellaravel-packagepackageresponseresponselaravellumenresponder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nnjeim-respond/health.svg)

```
[![Health](https://phpackages.com/badges/nnjeim-respond/health.svg)](https://phpackages.com/packages/nnjeim-respond)
```

###  Alternatives

[flugger/laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal and the elegancy of Laravel.

8901.5M5](/packages/flugger-laravel-responder)[laracrafts/laravel-url-shortener

Powerful URL shortening tools in Laravel

97110.7k](/packages/laracrafts-laravel-url-shortener)[proai/lumen-annotations

Route and event binding annotations for Laravel Lumen

1012.4k](/packages/proai-lumen-annotations)

PHPackages © 2026

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