Download the PHP package awaiskhan18/resman without Composer
On this page you can find all versions of the php package awaiskhan18/resman. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download awaiskhan18/resman
More information about awaiskhan18/resman
Files in awaiskhan18/resman
Package resman
Short Description ResMan is a PHP class that provides a convenient way to handle API responses with standard status codes and response structures. It includes methods for handling validation errors, success responses, and failure responses.
License MIT
Homepage https://github.com/awaiskhan18
Informations about the package resman
ResMan - Response Manager for API
ResMan is a PHP class that provides a convenient way to handle API responses with standard status codes and response structures. It includes methods for handling validation errors, success responses, and failure responses.
Installation
To use ResMan in your project, you can install it via Composer. Run the following command in your terminal:
composer require awaiskhan18/resman
Usage
First, import the ResMan class into your PHP file:
use Awaiskhan18\ResMan;
Handling Validation Errors
To handle validation errors, you can use the validationHandler method of the ResMan class. It takes a validator object as its parameter and returns a JSON response with the appropriate status code and error messages.
// Example usage of validationHandler
$validator = Validator::make($data, $rules);
if ($validator->fails()) {
return ResMan::validationHandler($validator);
}
Handling Success Responses
To handle success responses, you can use the successHandler method of the ResMan class. It takes the response data and a status description as its parameters and returns a JSON response with the success status code (200) and the provided data.
// Example usage of successHandler
$data = [
'user' => [
'name' => 'John Doe',
'email' => '[email protected]',
],
];
$statusDescription = 'Data retrieved successfully';
return ResMan::successHandler($data, $statusDescription);
Constants
ResMan includes the following constants that can be used to represent different HTTP status codes:
ResMan::STATUS_SUCCESS (200) - Represents a successful response.
ResMan::STATUS_ERROR (401) - Represents an error response.
License
This package is open-source software licensed under the MIT License. See the LICENSE file for more information.