Download the PHP package oguz-yilmaz/trammel without Composer
On this page you can find all versions of the php package oguz-yilmaz/trammel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oguz-yilmaz/trammel
More information about oguz-yilmaz/trammel
Files in oguz-yilmaz/trammel
Package trammel
Short Description Provides distinct exception handlers for Laravel
License MIT
Homepage https://github.com/oguz-yilmaz/trammel
Informations about the package trammel
About Trammel
Handling exceptions is vital for all sorts of applications.
Making it right and standardized increases the quality of your application
as well as making it easy to reason about. In laravel there is not much
configuration you can apply and there is only one place where you construct
all your exceptions, that is the Handler.php
. With the need of custom exception handling
this file becomes pretty ugly real quick having if-else statements all over the place.This
library provides default exception handling and standardized output formats for different
types of exceptions (Validation exceptions
, Ajax or Json exceptions
or combined
) as well as
distict handlers for each where you can extend and customize.
Installation
composer require oguz-yilmaz/trammel
Version Compatibility
Laravel | PHP | Trammel |
---|---|---|
7.x | 8.0+ | 1.x |
Exception handler types and default output formats
Trammel provides generic handlers for most situation. Each handler provides generic output formats that can be extended. See below for what they refer and what they offer as response format.
- Validation Exception Handler.
- Ajax Exception Handler.
- Json Exception Handler.
- Ajax Validation Exception Handler.
- Json Validation Exception Handler.
Usage
Default output formats
If you want to use default output formats you can simply extend Handler
class with
Trammel's BaseHandler
class in app/Exception
folder.
Customizing handlers
if you don't want to use default behaviour of a handler, you can extend it. First let's create
a new folder under app/Exception
called Handlers
to keep our custom exception handlers.
This will make it more tidy and clean.
Then you need to add these custom exception handlers to $handlers
property of the
App\Exception\Handler
class comes from Oguz\Trammel\Exception\BaseHandler
class.
How these exceptions will be triggered
So it's all great we have different kind of handlers for different kind of exceptions. But when exactly do we get those types of exceptions? Here is an example controller that will give you the idea about which exception types will be thrown in which situation.
To get detailed information for each exception type, see above.