f9webltd/laravel-api-response-helpers
Laravel package providing a simple trait to generate consistent JSON API responses across your app. Works with PHP 8.2+ and Laravel 11–13, offering helper methods for common success and error response patterns.
This package provides standardized helper methods for consistent API response formatting in Laravel applications. After installing via Composer (composer require f9webltd/laravel-api-response-helpers), begin by extending your base API controller with F9Web\ApiResponseHelpers\ApiResponseTrait. This exposes convenient methods like success(), error(), notFound(), and validationError() to return standardized JSON responses. The simplest first use case: replace manual response()->json() calls with $this->success(['data' => $model]).
{ "status": "success", "data": ..., "message": ... }).config/api-response-helpers.php (publish config with vendor:publish) to adjust status keys, message formatting, or HTTP codes.$this->validationError($validator) or wrap Model::firstOrFail() with $this->notFound('Resource not found').success($data, 'Operation completed', 201, $meta).$data passed to success() is serializable (avoid closures, resources).ApiResponseTrait does not intercept exceptions—combine with Laravel’s render() or global reportable callbacks for centralized error logging.How can I help you explore Laravel packages today?