Skip to content

therour/your-json-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YJResponse - Your Json Response

INSTALLATION

via Composer

composer require therour/your-json-response

For Laravel 5.4 and below Add Service Provider to config/app.php of your laravel project

'providers' => [
    ...
    Therour\YourJsonResponse\ServiceProvider::class,
] 

CONFIGURATION

publish configuration file

php artisan vendor:publish --provider=Therour\YourJsonResponse\ServiceProvider

the configuration file is located at your laravel's config directory by name yjresponse.php

USAGE

this package is bundled with named skeleton ok, you can edit the skeleton in config yjresponse.php

return response()->ok($data, $message = 'success', $code = 200);
// or
return response()->yourNamedSkeleton($data, $message = 'success', $code = 200);

CREATING SKELETON

open configuration file yjresponse.php

use code, message, data, type, and meta_page as value of skeleton to place it

EG:

'skeleton' => [
    ...
    // 'created' is the name of skeleton, and its value is the skeleton
    'created' => [
        'status' => [
            'code',
            'message'
        ],
        'result' => 'data'
    ]
],

at the same file, also define the default value

'defaults' => [
    ...
    'created' => [
        'code' => 201,
        'message' => 'Succesfully create the object'
    ]
]

Use your custom skeleton

return response()->created($product);

result

{
    "status": {
        "code": 201,
        "message": "Succesfully create the object"
    },
    "result": {
        "name": "Product X",
        "price": 6000,
        "weight": 500
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages