Looking to hire Laravel developers? Try LaraJobs

laravel-apiresponse maintained by sobhan-aali

Description
A Laravel package to standardize JSON API responses and centralize exception handling
Author
Last update
2025/08/17 13:00 (dev-master)
License
Links
Downloads
14

Comments
comments powered by Disqus

Standardizing API Responses and Handling All Exceptions

👋 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);
    });
});