sobhan-aali/laravel-apiresponse

A Laravel package to standardize JSON API responses and centralize exception handling

v1.0.0 2025-06-17 09:48 UTC

This package is not auto-updated.

Last update: 2025-06-17 10:12:18 UTC


README

👋 Introduction

Hi, I'm Sobhan Aali — thank you for choosing this package!

This package helps you standardize all your API JSON responses and handle exceptions gracefully across your Laravel project, including:

  • ✅ Consistent and customizable API Response formatting

  • ✅ Centralized Exception handling with meaningful JSON outputs

  • ✅ Easy-to-use Traits and response classes to speed up development

Installation:

composer require sobhan-aali/laravel-apiresponse

What’s Next?

Two files will be automatically created for you to customize:

  • Responses/ApiResponse.php

  • Traits/Exceptions.php

How to Enable Exception Handling

Add the following code to your bootstrap/app.php file to automatically handle exceptions using the package’s trait:

use App\Helpers\Exceptions;

$app->withExceptions(function ($exceptions) {
    
    $exceptions->renderable(function (Throwable $exception, $request) use ($handler) {
        return Exceptions::render($exception, $request);
    });
});