LaravelPackages.net
Acme Inc.
Toggle sidebar
petarpetkovic996/laravel-jsend-response

JSend Response Macro's for Laravel

5
0
1.0.0
About petarpetkovic996/laravel-jsend-response

petarpetkovic996/laravel-jsend-response is a Laravel package for jsend response macro's for laravel. It currently has 0 GitHub stars and 5 downloads on Packagist (latest version 1.0.0). Install it with composer require petarpetkovic996/laravel-jsend-response. Discover more Laravel packages by petarpetkovic996 or browse all Laravel packages to compare alternatives.

Last updated

Laravel JSend Response

Laravel Package Latest Version on Packagist Software License

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

Comments