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.
- 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, andCursorPaginator. - Resource Resolution: Seamlessly unwraps Laravel's
JsonResourceandResourceCollection. - Semantic Named Constructors: Clean static methods like
ApiResponse::success(),ApiResponse::validationError(), etc.
composer require weckhawk/laravel-api-responseuse Weckhawk\PrettyResponse\ApiResponse;
return ApiResponse::success(\$users, 'Users fetched successfully');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);return ApiResponse::notFound('User not found');
return ApiResponse::validationError([
'email' => ['The email field is required.']
]);The MIT License (MIT). Please see License File for more information.