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

Return API Response

Latest Version GitHub repo size GitHub Packagist Downloads

This package can return all sorts of responses for API

How to use this package:

Then include its service provider to your config/app.php

After that you can publish the config.

Then it's done!

In order to use this package you need to use this code inside your controllers

There are two ways to use this package

  1. Use it globally by adding using this code inside App\Http\Controllers\Controller.php
  2. Use it internally by adding the use code inside the controller you want to use it in.

Here are a few short examples of what you can do:

Expected response

You can use short params values (If it's string then it will be set as message, And if it's array then it will be set as data) Message:

Responses:

Data:

Response:

There are also more types such as not found exception

Response:

There is a list of all status strings you can use (otherwise you can use status code)

These are all the arguments you can send in apiResponse function

  1. type => the types we wrote earlier.
  2. filter_data => boolean.
  3. throw_exception => boolean.
  4. message => string.
  5. errorCode => Check MA\LaravelApiResponse\Enums\ErrorCodesEnum, you can either send it as integer, string or UnitEnum.
  6. status_code => integer (it will be applied only of type is not sent).

as example

Response:

There is validation function as example:

Note that you can either pass Illuminate\Http\Request Or Array as first parameter

Response:

You can use a pagination response as example:

Response:

List of all methods that can be used:

First parameter is paginated model, And the second parameter is to whether reverse the data or keep it at its order.

  1. The first parameter is for errors as it can be set as string or array.
  2. The second parameter determines whether to throw exception or not, default is true.
  3. The third parameter is for error code to be returned with response, it can either be an integer, string, null or UnitEnum instance

IMPORTANT
If error code is set to null it will return default error code if config returnDefaultErrorCodes is set to true

Return api forbidden error:

The first param is for message and can be set as null, The second one is for errors can be either array, string or null.

  1. The first parameter is for message as it can be set as string or null.
  2. The second parameter is for errors as it can be set as string or array.
  3. The third parameter is for error code to be returned with response, it can either be an integer, string, null or UnitEnum instance

Default message is Forbidden

PS: if errors is null it won't show errors property in response

Response:

Return api unauthenticated error:

The first param is for message and can be set as null, The second one is for errors can be either array, string or null.

Default message is Unauthenticated

PS: if errors is null it won't show errors property in response

Response:

There is api Validate

Same as Laravel This->validate() method first parameter is for data and the second one is for roles and the 3rd one for messages and the last one is for custom attributes. it should return the values of the validated data if passed or will throw exception using this trait if it failed.

There is die and dump data method

Response:

For error codes in config file

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

In order to publish the ErrorCodesEnum class

You can also specify the class name if you want

Otherwise it will generate it with the default class name as 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/database 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
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 ....