PHPackages                             shirokovnv/laravel-query-api-backend - 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. [Database &amp; ORM](/categories/database)
4. /
5. shirokovnv/laravel-query-api-backend

ActiveLibrary[Database &amp; ORM](/categories/database)

shirokovnv/laravel-query-api-backend
====================================

Unified API for running queries with eloquent models from any http client

0.1.0(5y ago)012MITPHPCI passing

Since Feb 6Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (11)Used By (0)

LaravelQueryApiBackend
======================

[](#laravelqueryapibackend)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c8fcbebbde9d166978a2bc1cc20f209f7b5fd081fcb39adccfa74853d68c2f0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736869726f6b6f766e762f6c61726176656c2d71756572792d6170692d6261636b656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shirokovnv/laravel-query-api-backend)[![Total Downloads](https://camo.githubusercontent.com/fcfe868e5ed2416e6e293f8bdc9e6a938c31bb3ba5b2d5c6a495c9a4983981f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736869726f6b6f766e762f6c61726176656c2d71756572792d6170692d6261636b656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shirokovnv/laravel-query-api-backend)[![Build Status](https://camo.githubusercontent.com/b43046eab213c666c8dc430929e36989bb4fcedcc4650ffab4719106f3dcd58d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736869726f6b6f766e762f6c61726176656c2d71756572792d6170692d6261636b656e642f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/shirokovnv/laravel-query-api-backend)[![StyleCI](https://camo.githubusercontent.com/47ce643c6fcfa2e277a17acbc34baab08352b853a1866d5907e1f6be08891509/68747470733a2f2f7374796c6563692e696f2f7265706f732f3333353036333833352f736869656c64)](https://styleci.io/repos/335063835)

Unified API for running queries with eloquent models from any http client.

For query data format and usage in frontend see [this package](https://github.com/shirokovnv/laravel-query-api-frontend)

Installation
------------

[](#installation)

Via Composer

```
$ composer require shirokovnv/laravel-query-api-backend
```

Usage
-----

[](#usage)

Ensure all migrations done

```
php artisan migrate
```

Publish configuration:

```
php artisan vendor:publish --provider="Shirokovnv\LaravelQueryApiBackend\LaravelQueryApiBackendServiceProvider" --tag=config
```

Once installed you can do stuff like this in Controller:

```
$queryRunner = LaravelQueryApiBackend::makeQueryRunnerInstance($request, $options);
$queryResult = $queryRunner->run();
$queryRunner->saveLog();

return response()->json($queryResult);
```

$request is Illuminate\\Http\\Request or Illuminate\\Foundation\\Http\\FormRequest

For available options see config section

Request must contain following keys:

> query\_data

> query\_mode

> client\_request\_id

This can be provided in middleware (check example controller and ClientRequestId middleware)

Example controller:

> Shirokovnv\\LaravelQueryApiBackend\\Http\\Controllers\\QueryApiController

### Available query modes:

[](#available-query-modes)

> transaction

runs a couple of queries as a whole. If one of the queries fails, transaction will be rolled back.

> multiple

runs a couple of queries individually.

all occurred errors will be added to the error pool with the rest of the result.

### Available types of queries:

[](#available-types-of-queries)

> create

> delete

> fetch (aka select)

> find

> update

> custom

### Authorization

[](#authorization)

Package provides a way to authorize actions with your queries.

By default no authorization needed.

1. To switch it on, at first, the model you want to authorize requests for, should implement Shirokovnv\\LaravelQueryApiBackend\\Support\\ShouldAuthorize interface.

The interface is simple and contains one static method:

```
    public static function shouldAuthorizeAbilities(): array;
```

This function must return array that contains names of abilities, for ex.

```
    return ['create', 'update', 'view', 'viewAny'];
```

Query type names and authorization ability names correlate as:

create -&gt; create

custom -&gt; custom

delete -&gt; delete

fetch -&gt; viewAny

find -&gt; view

update -&gt; update

2. The second options are default [laravel policies](https://laravel.com/docs/8.x/authorization) for your models.

Each policy contains specific methods, where you feel free to implement any logic for query authorization.

### Validation

[](#validation)

Each query can be validated the following way:

1. Use Laravel FormRequest generator for model.

For ex. for App\\Models\\User create request with name Models\\UserRequest

2. Model should implement Shirokovnv\\LaravelQueryApiBackend\\Support\\ShouldValidate interface

with one static method:

```
    public static function shouldValidateActions(): array;
```

For ex:

```
    return ['create', 'fetch', 'update', 'delete'];
```

Available list of actions is equal to list of query type names.

3. FormRequest action name to method correlation:

custom, create -&gt; POST

update -&gt; PATCH

delete -&gt; DELETE

find, fetch -&gt; GET

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Nickolai Shirokov](https://github.com/shirokovnv)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance59

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

7

Last Release

1835d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b6eee3a1104304577fab48df60136b13f5207972c2b644f1030c92ee28d9891?d=identicon)[shirokovnv](/maintainers/shirokovnv)

---

Top Contributors

[![shirokovnv](https://avatars.githubusercontent.com/u/43547352?v=4)](https://github.com/shirokovnv "shirokovnv (43 commits)")

---

Tags

apibackendeloquentlaravelpackagequerylaravelLaravelQueryApiBackend

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shirokovnv-laravel-query-api-backend/health.svg)

```
[![Health](https://phpackages.com/badges/shirokovnv-laravel-query-api-backend/health.svg)](https://phpackages.com/packages/shirokovnv-laravel-query-api-backend)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
