PHPackages                             bkstar123/laravel-api-buddy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bkstar123/laravel-api-buddy

ActiveLibrary[API Development](/categories/api)

bkstar123/laravel-api-buddy
===========================

A lightweight Laravel package helps you to quickly build a high-quality RESTful API with transformation, filtering, sorting, paginating and more

1.5.4(6y ago)117MITPHPPHP ^7.1.3

Since Jul 21Pushed 6y agoCompare

[ Source](https://github.com/bkstar123/laravel-api-buddy)[ Packagist](https://packagist.org/packages/bkstar123/laravel-api-buddy)[ RSS](/packages/bkstar123-laravel-api-buddy/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (32)Used By (0)

laravel-api-buddy
=================

[](#laravel-api-buddy)

> This lightweight Laravel package provides a powerful and simple toolset for quickly building high-quality RESTful API web services for Eloquent model resources with several advanced features such as schema transformation as well as sorting, filtering, selecting and paginating. Using together with the Laravel Passport package, you can have a full-fledge API system ready to serve any clients in a matter of minutes.

**Note**:
– This is not a silver bullet to solve all API problems, for example: it does not support `grouping`, `having` queries. It does not “apifyies” your model resources out of the box, it is just your buddy to build a powerful API system as quickly as possible. There are many rooms for you to personalize your API design, laravel-api-buddy makes your journey easier, more comfortable and saves you from doing some boilerplate coding.

– Please visit  for a detailed example about building API endpoints using ***bkstar123/laravel-api-buddy*** &amp; ***Laravel Passport***.

1 Requirements
--------------

[](#1-requirements)

It is recommended to install this package with PHP version 7.1.3+ and Laravel Framework version 5.6+

2 Installation
--------------

[](#2-installation)

```
composer require bkstar123/laravel-api-buddy

```

It will also install ***`barryvdh/laravel-cors`*** as a dependency. You can visit  for the detailed description of that package.

After installing, run: `php artisan apibuddy:publish`

It will copy all necessary configuration files to `/config/bkstar123_apibuddy.php` &amp; `/config/cors.php`

3 Configuration
---------------

[](#3-configuration)

`/config/cors.php` is the config file of ***`barryvdh/laravel-cors`*** package, you should consult its documentation for the further details.

`/config/bkstar123_apibuddy.php` is the package's main config file, it contains the following options:

- **`max_per_page`**: The maximum page size that a request can specify, by default it is 1000 items/page
- **`default_per_page`**: The default page size that will be applied if a request does not specify, by default it is 10 items/page
- **`replace_exceptionhandler`**: Whether or not to replace the Laravel default exception handler with the one provided by the package. It is recommended to be set to `true` (its default value) so that all exceptions can be converted to appropriate JSON responses
- **`useTransform`**: Whether or not to use transformation. It is recommmended to be set to `true` (its default value) for the best security protection. Since the underlying PDO DB driver does not support binding column names, see ; the transformation should always be used whenever you allow user input to dictate the column names referenced by your queries.

4 Usage
-------

[](#4-usage)

Supposing that we need to build some API endpoints for `users` resource.

### 4.1 General information

[](#41-general-information)

The package provides ***`\Bkstar123\ApiBuddy\Http\Controllers\ApiController`*** as the base API controller that can be extended by other API controllers. This `ApiController` has been automatically injected with an `Bkstar123\ApiBuddy\Contracts\ApiResponsible` instance.

You can quickly scalfold an API controller with `apibuddy:make --type=controller` command. For example:
`php artisan apibuddy:make UserController --type=controller`

All API controllers extending `ApiController` have access to the property **`$apiResponser`** which holds an `ApiResponsible` instance. The `ApiResponsible` instance exposes the following methods:

```
