radweb/tumble

for when it all comes tumbling down...

1.1.1 2016-01-25 12:56 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:20:40 UTC


README

687474703a2f2f692e696d6775722e636f6d2f51736c6872357a2e706e67

Latest Stable Version License

Tumble

for when it all comes tumbling down...

A collection of Exceptions roughly mapping to HTTP response status codes.

Also comes with a JSON formatter middleware for Laravel 5.x

Usage

If your entire application serves JSON (i.e. it's entirely an API) you can use this as an application-level Middleware. Add to your Kernel:

 protected $middleware = [
  // ...
  \Radweb\Tumble\FormatExceptionsMiddleware::class,
  // ...
];

If only a portion of your application serves JSON (i.e. you also have HTML views) you can use this a Route Middleware. Add to your Kernel:

 protected $routeMiddleware = [
  // ...
  'jsonExceptions' => \Radweb\Tumble\FormatExceptionsMiddleware::class,
  // ...
];

Then add the Middleware to your routes:

Route::group(['prefix' => '/api', 'middleware' => ['jsonExceptions']], function() {
  Route::get('/', function() {
    // ...
  });
});