| Package Data | |
|---|---|
| Maintainer Username: | BWT group |
| Maintainer Contact: | chesanovskiydv@gmail.com (Chesanovskiy Denis) |
| Package Create Date: | 2018-04-07 |
| Package Last Update: | 2022-11-19 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-26 03:02:02 |
| Package Statistics | |
|---|---|
| Total Downloads: | 10,196 |
| Monthly Downloads: | 66 |
| Daily Downloads: | 0 |
| Total Stars: | 1 |
| Total Watchers: | 2 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
This package allows to easily and quickly setup basics for API.
Install this package with composer using the following command:
composer require bwt-team/laravel-api
When composer updated, add service provider into providers array in config/app.php.
BwtTeam\LaravelAPI\Providers\ApiServiceProvider::class
This service provider will register api macros for more comfortable work.
You will have the following format of call available in api format:
response()->api($data)
In full format it will look as following:
new \BwtTeam\LaravelAPI\Response\ApiResponse($data)
Also, this service provider will allow to publish config file in order to update package settings according to your needs. Use the following command for publication:
php artisan vendor:publish --provider="BwtTeam\LaravelAPI\Providers\ApiServiceProvider" --tag=config
To make all responses (including alerts etc) be sent in the same format, change class parent to \BwtTeam\LaravelAPI\Exceptions\Handler in App\Exceptions\Handler class
class Handler extends \BwtTeam\LaravelAPI\Exceptions\Handler
And middleware \BwtTeam\LaravelAPI\Middleware\Api should be connected to specific path (or the whole app) to make this path be handled as API method.
If you are using App\Http\Requests class instances for validation, you need to inherit from BwtTeam\LaravelAPI\Requests\ApiRequest, rather than Illuminate\Foundation\Http\FormRequest.
After composer update register a service provider, by adding the following lines into bootstrap/app.php:
$app->register(\BwtTeam\LaravelAPI\Providers\ApiServiceProvider::class);
Copy config file vendor/bwt-team/laravel-api/config/api.php into config directory, which is stored in root directory (or create it yourself if it is missing) and set it up according to your needs.
To load settings from this file in bootstrap/app.phpadd the following lines:
$app->configure('api');
To make all responses (including alerts etc) be sent in the same format, change class parent to BwtTeam\LaravelAPI\Exceptions\LumenHandler in App\Exceptions\Handler
class Handler extends \BwtTeam\LaravelAPI\Exceptions\LumenHandler
And middleware \BwtTeam\LaravelAPI\Middleware\Api should be connected to specific path (or the whole app) to make this path be handled as API method.
This package is using MIT.