petarpetkovic996 / laravel-jsend-response
JSend Response Macro's for Laravel
1.0.0
2023-08-10 00:34 UTC
Requires
- php: >=5.6
- laravel/framework: >=5.4
Requires (Dev)
- phpunit/phpunit: ^5.7
README
This package defines JSend macros for the response in Laravel.
Installation
You can install the package via Composer:
composer require petarpetkovic996/laravel-jsend-response
Usage
Success
$data = [ "first_name" => "Petar", "last_name" => "Petkovic" ]; return response()->success($data, 201);
Result
{ "status": "success", "data": { "first_name": "Petar", "last_name": "Petkovic" } }
With the HTTP Status Code: 201
Fail
$data = [ 'first_name' => 'A first_name is required' 'last_name' => 'A last_name is required' ]; return response()->fail($data, 422);
Result
{ "status": "fail", "data": { "first_name": "A first_name is required" "last_name": "A last_name is required" } }
With the HTTP Status Code: 422
Error
return response()->error('Unable to communicate with database', 500);
Result
{ "status": "error", "message": "Unable to communicate with database" }
With the HTTP Status Code: 500