Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel API Response Builder

A fluent, expressive, and consistent API response wrapper for Laravel applications. It helps you standardize JSON responses, handle paginators automatically, and keep your controllers clean.

Features

  • Standardized Structure: Ensures every JSON response follows a predictable format (success, message, data, errors, meta).
  • Smart Pagination Handling: Automatically extracts metadata from Eloquent LengthAwarePaginator, SimplePaginator, and CursorPaginator.
  • Resource Resolution: Seamlessly unwraps Laravel's JsonResource and ResourceCollection.
  • Semantic Named Constructors: Clean static methods like ApiResponse::success(), ApiResponse::validationError(), etc.

Installation

composer require weckhawk/laravel-api-response

Basic Usage

Success Response

use Weckhawk\PrettyResponse\ApiResponse;

return ApiResponse::success(\$users, 'Users fetched successfully');

Paginated Response

Pass any Laravel paginator directly into the success method. The package will automatically append the meta object:

\$paginatedUsers = User::paginate(15);

return ApiResponse::success(\$paginatedUsers);

Error Responses

return ApiResponse::notFound('User not found');

return ApiResponse::validationError([
    'email' => ['The email field is required.']
]);

License

The MIT License (MIT). Please see License File for more information.

About

A fluent and consistent API response builder for Laravel applications.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages