PHPackages                             farshidrezaei/vandar-responder - 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. farshidrezaei/vandar-responder

ActiveLibrary[API Development](/categories/api)

farshidrezaei/vandar-responder
==============================

Vandar Responder Laravel Packagee

2.0.2(9mo ago)510.2k1MITPHPPHP ^7.4|^8.0

Since Jul 17Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/farshidrezaei/vandar-responder)[ Packagist](https://packagist.org/packages/farshidrezaei/vandar-responder)[ RSS](/packages/farshidrezaei-vandar-responder/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)DependenciesVersions (18)Used By (0)

Responder, Vandar response handler laravel package
==================================================

[](#responder-vandar-response-handler-laravel-package)

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

[](#installation)

### composer

[](#composer)

```
composer require farshidrezaei/vandar-responder
```

you must publish config and languages files:

```
#config
php artisan vendor:publish --provider="FarshidRezaei\VandarResponder\Providers\ResponderServiceProvider" --tag="config"

#language
php artisan vendor:publish --provider="FarshidRezaei\VandarResponder\Providers\ResponderServiceProvider" --tag="language"
```

after publish config file you can customize string errors. string errors will use in failure responses.

you can access errors like bellow:

```
config('responder.errors.YOUR_ERROR')
config('responder.errors.INTERNAL_ERROR')
config('responder.errors.EXTERNAL_SERVICE_ERROR')
```

you can access translation like bellow:

```
__('responder::exceptions.YOUR_ERROR')
__('responder::exceptions.validation')
```

Usage
-----

[](#usage)

### Signatures of methods:

[](#signatures-of-methods)

```
Responder::success(?string $message = null, mixed $data = null): Illuminate\Http\JsonResponse

Responder::successResourceCollection(null|string $message = null, Illuminate\Http\Resources\Json\AnonymousResourceCollection $data) :lluminate\Http\Resources\Json\AnonymousResourceCollection

Responder::failure(int $errorCode, string $stringErrorCode, null|string $message = null, array|null $errors = [], array|null $data = []): Illuminate\Http\JsonResponse
```

Here's a quick example:

#### You can use function added macro on response class:

[](#you-can-use-function-added-macro-on-response-class)

```
// php 8
return response()->failure(
            errorCode: Response::HTTP_INTERNAL_SERVER_ERROR,// 500
            stringErrorCode: config('responder.errors.INTERNAL_ERROR'),
            message: "Service isn't available now. try again later.",
            data:['foo'=>'bar']
        );
```

#### Or call function from facade directly:

[](#or-call-function-from-facade-directly)

```
use FarshidRezaei\VandarResponder\Services\Responder;

// php 8
 return Responder::failure(
            errorCode: Response::HTTP_INTERNAL_SERVER_ERROR,// 500
            stringErrorCode: config('responder.errors.INTERNAL_ERROR'),
            message: "Service isn't available now. try again later.",
            data:['foo'=>'bar']
        );

// php 7.4
 return Responder::failure(
            Response::HTTP_INTERNAL_SERVER_ERROR,// 500
            config('responder.errors.INTERNAL_ERROR'),
            "Service isn't available now. try again later.",
            ['foo'=>'bar']
        );
```

And you will get bellow response:

```
{
  "message": "Service isn't available now. try again later.",
  "code": "internal_error",
  "data": {
        "foo":"bar"
  }
}

```

#### Also you can use `responder()` helper function :

[](#also-you-can-use-responder-helper-function-)

```
// php 8
 return responder()->success(
                message:"User Info",
                data: [
                    "name"=>"Farshid",
                    "company"=>"Vandar",
                    "Position"=>"Full-Stack Web Developer"
                ]
        );
```

and you will get bellow response:

```
{
    "message": "User Info",
    "data": {
        "name": "Farshid",
        "company": "Vandar",
        "Position": "Full-Stack Web Developer"
    }
}
```

if you want to respond laravel ResourceCollection do like bellow:

```
// php 8
    $users=User::paginate();
    return Responder::successResourceCollection(
        message: 'User List.',
        data: USerResource::collection($users)
    );
```

Api Exception Handler
=====================

[](#api-exception-handler)

To standardize the responses, the exceptions must also follow vandar standards. laravel has itself rules to show response of exceptions. with this feature of this package you can customize every laravel exceptions.

for use this feature please add bellow code to `render()` function in `app/Exceptions/Handler.php`:

```
    public function render($request, Throwable $e): \Illuminate\Http\Response|JsonResponse|Response
    {
        //...
        if ($request->expectsJson() && $exceptionResponse = ApiExceptionHandler::handle($e)) {
            return $exceptionResponse;
        }
        //...
        return parent::render($request, $e);
    }
```

we handle and customize some exceptions. after publish configs, you can see it in `config/responder.php` as `customExceptions`key:

```
  'customExceptions' => [
        RuntimeException::class => CustomDefaultException::class,
        Exception::class => CustomDefaultException::class,
        ValidationException::class => CustomValidationException::class,
        NotFoundHttpException::class => CustomNotFoundHttpException::class,
        MethodNotAllowedException::class => CustomMethodNotAllowed::class,
        ModelNotFoundException::class => CustomNotFoundHttpException::class,
        AuthenticationException::class => CustomAuthenticationException::class,
        AuthorizationException::class => CustomUnauthorizedException::class,
        UnauthorizedHttpException::class => CustomUnauthorizedException::class,
        ThrottleRequestsException::class => CustomThrottleRequestsException::class
    ]
```

you can customize,add,edit and override any of classes.

also you can publish this classes by run this command:

```
#customExceptions
php artisan vendor:publish --provider="FarshidRezaei\VandarResponder\Providers\ResponderServiceProvider" --tag="customExceptions"
```

**don't forget change namespace of classes after publish**

customException structure
-------------------------

[](#customexception-structure)

```
class CustomDefaultException extends AbstractApiCustomException implements ApiCustomExceptionInterface
{
    public function __construct(?Exception $exception)
    {
        $this->errorCode = Response::HTTP_INTERNAL_SERVER_ERROR; // exception Status Code

        $this->stringErrorCode = config('responder.errors.EXTERNAL_SERVICE_ERROR'); // string error code

        $this->errorMessage = __('responder::exceptions.generalServerError'); // message of error

        parent::__construct();
    }
}
```

if you assign it for a laravel exception it will call responder `failure()` function and return json response to client.

```
//with status 500
{
    "message": "خطایی رخ داده است، لطفا دوباره تلاش کنید",
    "code": "external_service_error"
}
```

### tip

[](#tip)

if you want to create a non-laravel exception and throw it, you can call `Responder::failure()` function in render of exception.

it will return standard json.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance56

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~78 days

Recently: every ~237 days

Total

15

Last Release

294d ago

Major Versions

1.5.1 → 2.0.02022-12-18

1.5.3 → 2.0.22025-07-22

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

1.3.1PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/39159567f8a54c452a911b722d524b66bd673c4cb02a4e989eaa8eb29d84eee0?d=identicon)[farshidrezaei](/maintainers/farshidrezaei)

---

Top Contributors

[![farshidrezaei](https://avatars.githubusercontent.com/u/16887867?v=4)](https://github.com/farshidrezaei "farshidrezaei (18 commits)")

### Embed Badge

![Health badge](/badges/farshidrezaei-vandar-responder/health.svg)

```
[![Health](https://phpackages.com/badges/farshidrezaei-vandar-responder/health.svg)](https://phpackages.com/packages/farshidrezaei-vandar-responder)
```

###  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)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

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

PHP wrapper for the Meilisearch API

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

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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