{"id":20811206,"url":"https://github.com/shirokovnv/laravel-query-api-backend","last_synced_at":"2026-04-25T09:36:47.758Z","repository":{"id":54429143,"uuid":"335063835","full_name":"shirokovnv/laravel-query-api-backend","owner":"shirokovnv","description":"Unified API for running queries with eloquent models from any http client","archived":false,"fork":false,"pushed_at":"2026-01-20T00:21:01.000Z","size":87,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-20T07:41:55.133Z","etag":null,"topics":["api","backend","eloquent","laravel","package","query"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shirokovnv.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-01T19:41:03.000Z","updated_at":"2026-01-20T00:21:05.000Z","dependencies_parsed_at":"2022-08-13T15:20:41.940Z","dependency_job_id":null,"html_url":"https://github.com/shirokovnv/laravel-query-api-backend","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/shirokovnv/laravel-query-api-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirokovnv%2Flaravel-query-api-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirokovnv%2Flaravel-query-api-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirokovnv%2Flaravel-query-api-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirokovnv%2Flaravel-query-api-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shirokovnv","download_url":"https://codeload.github.com/shirokovnv/laravel-query-api-backend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirokovnv%2Flaravel-query-api-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32257754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backend","eloquent","laravel","package","query"],"created_at":"2024-11-17T20:37:51.948Z","updated_at":"2026-04-25T09:36:47.727Z","avatar_url":"https://github.com/shirokovnv.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LaravelQueryApiBackend\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Build Status][ico-travis]][link-travis]\n[![StyleCI][ico-styleci]][link-styleci]\n\nUnified API for running queries with eloquent models from any http client.\n\nFor query data format and usage in frontend see [this package](https://github.com/shirokovnv/laravel-query-api-frontend)\n\n## Installation\n\nVia Composer\n\n``` bash\n$ composer require shirokovnv/laravel-query-api-backend\n```\n\n## Usage\n\nEnsure all migrations done\n\n``` bash\nphp artisan migrate\n```\n\nPublish configuration: \n\n```php\nphp artisan vendor:publish --provider=\"Shirokovnv\\LaravelQueryApiBackend\\LaravelQueryApiBackendServiceProvider\" --tag=config\n```\n\nOnce installed you can do stuff like this in Controller:\n\n```php\n$queryRunner = LaravelQueryApiBackend::makeQueryRunnerInstance($request, $options);\n$queryResult = $queryRunner-\u003erun();\n$queryRunner-\u003esaveLog();\n      \nreturn response()-\u003ejson($queryResult);\n```\n\n$request is Illuminate\\Http\\Request or Illuminate\\Foundation\\Http\\FormRequest\n\nFor available options see config section\n\nRequest must contain following keys:\n\n\u003e query_data\n\n\u003e query_mode\n\n\u003e client_request_id\n\nThis can be provided in middleware (check example controller and ClientRequestId middleware)\n\nExample controller: \n\n\u003e Shirokovnv\\LaravelQueryApiBackend\\Http\\Controllers\\QueryApiController\n\n### Available query modes:\n\n\u003e transaction \n\nruns a couple of queries as a whole. If one of the queries fails,\ntransaction will be rolled back.\n\n\u003e multiple\n\nruns a couple of queries individually.\n\nall occurred errors will be added to the error pool with the rest of the result.\n\n### Available types of queries:\n\n\u003e create\n\n\u003e delete\n\n\u003e fetch (aka select)\n\n\u003e find\n\n\u003e update\n\n\u003e custom\n\n### Authorization\n\nPackage provides a way to authorize actions with your queries.\n\nBy default no authorization needed.\n\n1. To switch it on, at first, the model you want to authorize requests for, should implement Shirokovnv\\LaravelQueryApiBackend\\Support\\ShouldAuthorize interface.\n\nThe interface is simple and contains one static method: \n\n```php\n    public static function shouldAuthorizeAbilities(): array;\n```\n\nThis function must return array that contains names of abilities, for ex. \n\n```php\n    return ['create', 'update', 'view', 'viewAny'];\n```\n\nQuery type names and authorization ability names correlate as: \n\ncreate -\u003e create\n\ncustom -\u003e custom\n\ndelete -\u003e delete\n\nfetch -\u003e viewAny\n\nfind -\u003e view\n\nupdate -\u003e update\n\n2. The second options are default [laravel policies](https://laravel.com/docs/8.x/authorization) for your models.\n\nEach policy contains specific methods, where you feel free to implement any \nlogic for query authorization.\n\n### Validation\n\nEach query can be validated the following way: \n\n1. Use Laravel FormRequest generator for model.\n\nFor ex. for App\\Models\\User create request with name Models\\UserRequest\n\n2. Model should implement Shirokovnv\\LaravelQueryApiBackend\\Support\\ShouldValidate interface\n\nwith one static method: \n\n```php\n    public static function shouldValidateActions(): array;\n```\n\nFor ex: \n\n```php\n    return ['create', 'fetch', 'update', 'delete'];\n```\n\nAvailable list of actions is equal to list of query type names.\n\n3. FormRequest action name to method correlation: \n\ncustom, create -\u003e POST\n\nupdate -\u003e PATCH\n\ndelete -\u003e DELETE\n\nfind, fetch -\u003e GET\n\n## Change log\n\nPlease see the [changelog](changelog.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [contributing.md](contributing.md) for details and a todolist.\n\n## Security\n\nIf you discover any security related issues, please email shirokovnv@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Nickolai Shirokov][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nMIT. Please see the [license file](license.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/shirokovnv/laravel-query-api-backend.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/shirokovnv/laravel-query-api-backend.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/shirokovnv/laravel-query-api-backend/master.svg?style=flat-square\n[ico-styleci]: https://styleci.io/repos/335063835/shield\n\n[link-packagist]: https://packagist.org/packages/shirokovnv/laravel-query-api-backend\n[link-downloads]: https://packagist.org/packages/shirokovnv/laravel-query-api-backend\n[link-travis]: https://travis-ci.org/shirokovnv/laravel-query-api-backend\n[link-styleci]: https://styleci.io/repos/335063835\n[link-author]: https://github.com/shirokovnv\n[link-contributors]: ../../contributors\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirokovnv%2Flaravel-query-api-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshirokovnv%2Flaravel-query-api-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirokovnv%2Flaravel-query-api-backend/lists"}