Unified API for running queries with eloquent models from any http client
shirokovnv/laravel-query-api-backend is a Laravel package for unified api for running queries with eloquent models from any http client.
It currently has 0 GitHub stars and 12 downloads on Packagist (latest version 0.1.0).
Install it with composer require shirokovnv/laravel-query-api-backend.
Discover more Laravel packages by shirokovnv
or browse all Laravel packages to compare alternatives.
Last updated
Unified API for running queries with eloquent models from any http client.
For query data format and usage in frontend see this package
Via Composer
$ composer require shirokovnv/laravel-query-api-backend
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
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.
create
delete
fetch (aka select)
find
update
custom
Package provides a way to authorize actions with your queries.
By default no authorization needed.
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 -> create
custom -> custom
delete -> delete
fetch -> viewAny
find -> view
update -> update
Each policy contains specific methods, where you feel free to implement any logic for query authorization.
Each query can be validated the following way:
For ex. for App\Models\User create request with name Models\UserRequest
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.
custom, create -> POST
update -> PATCH
delete -> DELETE
find, fetch -> GET
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.