Download the PHP package vahid/respond without Composer
On this page you can find all versions of the php package vahid/respond. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vahid/respond
More information about vahid/respond
Files in vahid/respond
Package respond
Short Description Easy JSON response for Laravel and Lumen, a useful package for handle your RESTful API endpoint
License MIT
Homepage https://github.com/vahid-almasi
Informations about the package respond
Laravel Respond
This package is provided to be used on lumen and laravel framework v5 and upper and it gives clean methods to handle json response with specific predetermined messages.
Requirement
- Laravel >=5.1
- Lumen
- PHP >=5.5
Install
Via Composer
Go to your project path and run this code in your terminal
Or edit your composer.json to require the package.
Then run composer update
in your terminal to pull it in
Config
Laravel
you will need to add the service provider to the providers array in your config/app.php
as follows:
Next, also in the app.php config file, under the aliases array, you may want to add the Respond facade.
Laravel 4:
Laravel 5:
Lumen
Added into providers
you will need to add the service provider beside another register service providers on bootstrap/app.php
as follows:
after that you need create a helper and add config_path
function.
Create config_path
helper for Lumen
Create a file called GeneralHelpers.php in the app/Helpers directory. Paste the code inside it.
Go to composer.json and add files to autoload so that it looks like this:
Run composer dump-autoload to load the newly created helpers file.
Usage
You 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:
When deletion action succeeds:
When updating succeeds:
When insertion succeeds:
When deletion action fails:
When updating fails:
when insertion fails:
Not Found Error:
When db connetion is refused:
When parameters entered are wrong:
When requested method is not allowed:
Validation errors:
Note: If you use Laravel FormRequest, to prevent iteration, we recommend try this method in App\Http\Request.php and override response method of Illuminate FormRequest
customization
Set custom message for methods is like this:
And you can do more:
License
The MIT License (MIT). Please see License File for more information.