PHPackages                             ysm/responsable - 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. ysm/responsable

ActiveLibrary[API Development](/categories/api)

ysm/responsable
===============

A Laravel package for standardized JSON response macros

1.0.0(7mo ago)9697↑125.9%1MITPHPPHP &gt;=7.2

Since Sep 21Pushed 7mo agoCompare

[ Source](https://github.com/DevYSM/responsable)[ Packagist](https://packagist.org/packages/ysm/responsable)[ RSS](/packages/ysm-responsable/feed)WikiDiscussions master Synced 1mo ago

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

YSM Responsable
===============

[](#ysm-responsable)

A Laravel package that provides standardized response macros for both JSON (API) and web (redirect) responses, along with helper functions to manage session data. It adds `success` and `error` macros to the `Response` facade (for JSON) and `RedirectResponse` class (for web), and provides `responsable()` and `responsable_forget()` helpers for session data management in Laravel 12+ applications.

Features
--------

[](#features)

- `success` and `error` macros for JSON API responses with optional pagination metadata.
- `success` and `error` macros for web redirects with session-based flash or persistent data.
- `success()` and `error()` helper functions for cleaner syntax in controllers.
- `responsable()` helper to retrieve session data in a structured format.
- `responsable_forget()` helper to clear session data.
- Supports Laravel's pagination (`LengthAwarePaginator`, `Paginator`, `CursorPaginator`).
- Lightweight and easy to integrate.

Requirements
------------

[](#requirements)

- PHP 7.2 or higher
- Laravel 6.0 or higher

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

[](#installation)

Install the package via Composer:

```
composer require ysm/responsable
```

The package uses Laravel's auto-discovery to register the `ResponsableServiceProvider`. If auto-discovery is disabled, manually add the provider to `config/app.php`:

```
'providers' => [
    // Other providers
    YSM\Responsable\ResponsableServiceProvider::class,
],
```

Usage
-----

[](#usage)

The package provides `success` and `error` macros for both JSON responses (via `Response` facade or `response()` helper) and web redirects (via `RedirectResponse`), along with helper functions `responsable()` and `responsable_forget()` for session data management.

### JSON Response Macros

[](#json-response-macros)

#### Example 1: Fetching a Collection of Posts

[](#example-1-fetching-a-collection-of-posts)

Return a collection of posts with a JSON success response:

```
