fernandozueet/response-laravel

Library for standardization of error messages and success of api json.

1.0.1 2019-04-30 18:14 UTC

This package is auto-updated.

Last update: 2024-04-29 04:06:30 UTC


README

Library for standardization of error messages and success of api json.

Requirements

  • PHP 7.0 or newer;
  • Laravel 5.8 or newer;

Installation

composer require fernandozueet/response-laravel

Response status 204:

status 204

return respond_empty();

Response success:

status 200

return respond_success('Record changed successfully.');

//or 

//create translation file
return respond_success('filex.record_success');
{
    "status": "success",
    "message": "Record changed successfully."
}

Response success and included data:

status 200

return respond_success('Record changed successfully', [ 'type' => 1 ]);
{
    "status": "success",
    "message": "Record changed successfully.",
    "data": {
        "type": 1
    }
}

Response created:

status 201

return respond_created('Record created successfully.');
{
    "status": "success",
    "message": "Record created successfully."
}

Response created and included data:

status 201

return respond_created('Record created successfully.', [ 'type' => 1 ]);
{
    "status": "success",
    "message": "Record created successfully.",
    "data": {
        "type": 1
    }
}

Response error:

status 400

return respond_error('Error while changing registry.');
{
    "status": "error",
    "message": "Error while changing registry."
}

Response error and included data:

status 400

return respond_error('Error while changing registry.', [ 'type' => 1 ]);
{
    "status": "error",
    "message": "Error while changing registry.",
    "data": {
        "type": 1
    }
}

Response error:

status 401

return respond_unauthorized();
{
    "status": "error",
    "message": "Unauthenticated."
}

Contributing

Please see CONTRIBUTING for details.

Security

If you discover security related issues, please email fernandozueet@hotmail.com instead of using the issue tracker.

Credits

License

The package is licensed under the MIT license. See License File for more information.