Download the PHP package i3rror/lapi-response without Composer

On this page you can find all versions of the php package i3rror/lapi-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lapi-response

Laravel API Response

Latest Version GitHub repo size GitHub Packagist Downloads

This package provides comprehensive functionality for handling and returning all types of API responses in Laravel applications. It offers consistent response formatting, error handling, and pagination support.

Installation and Setup

Step 1: Install via Composer

Step 2: Register Service Provider

Include the service provider in your config/app.php or in bootstrap/providers.php if you're using laravel 11:

Step 3: Publish Configuration

Run the following command to publish the package configuration:

Basic Implementation

To utilize this package, you'll need to use the APIResponseTrait in your controllers:

You have two implementation options:

  1. Global Implementation: Add the trait to App\Http\Controllers\Controller.php to make it available across all controllers
  2. Local Implementation: Add the trait only to specific controllers where API responses are needed

Usage Examples

Basic Response Example

Expected response:

Simplified Parameter Usage

You can use short parameter values in two ways:

Message Example:

Response:

Data Example:

Response:

API Stream Response

The stream response feature requires a Generator class as the first parameter:

Response:

Error Handling

Not Found Exception

Important Notes:

Response:

Available Status Types

API Response Parameters

The apiResponse function accepts the following arguments:

  1. type => Response type (from the types listed above)
  2. filter_data => boolean
  3. throw_exception => boolean
  4. message => string
  5. errorCode => Check MA\LaravelApiResponse\Enums\ErrorCodesEnum (can be integer, string, or UnitEnum)
  6. status_code => integer (applies only if type is not sent)

Example with Error Code:

Response:

Validation Support

Note: The first parameter can be either Illuminate\Http\Request or an array

Response for validation failure:

Pagination Support

Response:

Available Methods

Parameters:

Error Handling Methods:

Parameters:

  1. First parameter: errors (string or array)
  2. Second parameter: whether to throw exception (default: true)
  3. Third parameter: error code (integer, string, null, or UnitEnum instance)

IMPORTANT: If error code is null, it will return the default error code if config returnDefaultErrorCodes is true

Forbidden Error Response

Parameters:

  1. First parameter: message (string or null)
  2. Second parameter: errors (string, array, or null)
  3. Third parameter: error code (integer, string, null, or UnitEnum instance)

Default message is "Forbidden"

Note: If errors is null, the errors property won't appear in the response

Response:

Unauthenticated Error Response

Parameters:

Note: If errors is null, the errors property won't appear in the response

Response:

API Validation

Follows Laravel's validate() method pattern:

Returns validated data on success or throws an exception using this trait on failure.

API Validation (Request)

Add this trait to your requests to handle validation errors.

Debug Helper

Response:

Error Codes Configuration

The package provides extensive error code configuration options:

  1. Enable/disable error codes
  2. Set error code enum class or custom enum class
  3. Set error codes output type (string or integer)
  4. Enable/disable returning default error codes if set as null
  5. Set error codes defaults for error functions

Publishing Error Codes Enum

Basic usage:

With custom class name:

If no custom name is specified, it will generate with the default class name "ErrorCodesEnum"

Contributors

Ahmed
Ahmed Elrayes
Mohamed
Mohamed Aboushady

License

The MIT License (MIT). Please see License File for more information.


All versions of lapi-response with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/auth Version >=10.43.0
illuminate/config Version >=10.43.0
illuminate/container Version >=10.43.0
illuminate/contracts Version >=10.43.0
illuminate/http Version >=10.43.0
illuminate/pagination Version >=10.43.0
illuminate/routing Version >=10.43.0
illuminate/support Version >=10.43.0
illuminate/validation Version >=10.43.0
symfony/http-foundation Version ^6.0 || ^7.0
psr/log Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package i3rror/lapi-response contains the following files

Loading the files please wait ....