This package is provided to be used on laravel framework v5 and upper and it gives clean methods to handle json response with specific predetermined messages.
- Laravel ^5.1
- PHP ^5.5
The package is in process.
Via Composer
$ composer require Anetwork/Respond##Config
Add the following provider to providers part of config/app.php
Anetwork\Respond\RespondServiceProvider::classand the following Facade to the aliases part
'Respond' => Anetwork\Respond\Facades\Respond::classYou can use these methods in deffernt ways:
There are hot ones for quick usage, besides some provided to manage outputs on your own way
Some are shown below:
When request succeeds and contains data to return as a result:
Respond::succeed( $data );When deletion action succeeds:
Respond::deleteSucceeded();When updating succeeds:
Respond::updateSucceeded();When insertion succeeds:
Respond::insertSucceeded();When deletion action fails:
Respond::deleteFaild();When updating fails:
Respond::updateFaild();when insertion fails:
Respond::insertFaild();Not Found Error:
Respond::notFound();When db connetion is refused:
Respond::connectionRefused();When parameters entered are wrong:
Respond::wrongParameters();When requested method is not allowed:
Respond::methodNotAllowed();Respond::requestFieldNotFound();Validation errors:
Respond::validationErrors( $data );Note: If you use laravel FormRequest,to prevnet iteration, we recommond try this method in App\Http\Request.php and override response method of Illuminate FormRequest
###customization Set custom message for methods is like this:
Respond::notFound( 'Leave it empty or enter your custom message here' );And you can do more:
Respond::setStatusCode( 200 )->setStatusText( 'succeed' )->respondWithMessage( 'Your custom message' );The MIT License (MIT). Please see License File for more information.
