Download the PHP package ysm/responsable without Composer
On this page you can find all versions of the php package ysm/responsable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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
successanderrormacros for JSON API responses with optional pagination metadata.successanderrormacros for web redirects with session-based flash or persistent data.success()anderror()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
- PHP 7.2 or higher
- Laravel 6.0 or higher
Installation
Install the package via Composer:
The package uses Laravel's auto-discovery to register the ResponsableServiceProvider. If auto-discovery is disabled,
manually add the provider to config/app.php:
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
Example 1: Fetching a Collection of Posts
Return a collection of posts with a JSON success response:
Output:
Example 2: Fetching Paginated Posts
Return paginated posts with metadata:
Output:
Example 3: Handling JSON Errors
Return an error response when a condition fails:
Output (Error):
Use apiSuccess() || apiError() Helpers
You can also use the success() and error() helpers for cleaner syntax:
Web Redirect Macros
Example 4: Success Redirect with Session Data
Redirect with a success message stored in the session:
Session Data (accessible via responsable()):
Example 5: Error Redirect with Validation Errors
Redirect with an error message and validation errors:
Session Data (accessible via responsable()):
Example 6: Persistent Session Data
Use $persist = true to store data beyond the next request:
Helper Functions
responsable()
Retrieve session data stored by web macros in a structured array:
Example in a Controller:
responsable_forget()
Clear session data stored by web macros:
Example in a Controller:
Accessing Session Data in Views
Use the responsable() helper in Blade views for a cleaner interface:
Alternatively, access session data directly:
Macro Signatures
-
JSON
successMacro: -
JSON
errorMacro: -
Web
successMacro: - Web
errorMacro:
You can also use the response() helper for JSON responses:
IDE Support
To enable autocompletion for the success, error, responsable(), and responsable_forget() functions in your IDE (
e.g., PHPStorm, VS Code):
-
Install the
barryvdh/laravel-ide-helperpackage: - Generate the IDE helper file:
This creates a _ide_helper.php file that includes the success and error macros for both Response
and RedirectResponse, as well as the responsable() and responsable_forget() helpers.
License
This package is open-sourced under the MIT License.
All versions of responsable with dependencies
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0