{"id":15019812,"url":"https://github.com/williamoliveira/eloquent-array-query-builder","last_synced_at":"2025-05-02T12:32:14.742Z","repository":{"id":57080814,"uuid":"53277655","full_name":"williamoliveira/eloquent-array-query-builder","owner":"williamoliveira","description":"Query Laravel Eloquent with and associative array","archived":false,"fork":false,"pushed_at":"2020-08-18T20:08:28.000Z","size":44,"stargazers_count":18,"open_issues_count":2,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-30T11:19:09.565Z","etag":null,"topics":["eloquent","laravel","laravel5","php","query-builder"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/williamoliveira.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-06T21:40:35.000Z","updated_at":"2024-11-26T11:14:15.000Z","dependencies_parsed_at":"2022-08-24T14:57:57.712Z","dependency_job_id":null,"html_url":"https://github.com/williamoliveira/eloquent-array-query-builder","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamoliveira%2Feloquent-array-query-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamoliveira%2Feloquent-array-query-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamoliveira%2Feloquent-array-query-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamoliveira%2Feloquent-array-query-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamoliveira","download_url":"https://codeload.github.com/williamoliveira/eloquent-array-query-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252038250,"owners_count":21684661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["eloquent","laravel","laravel5","php","query-builder"],"created_at":"2024-09-24T19:54:08.873Z","updated_at":"2025-05-02T12:32:09.733Z","avatar_url":"https://github.com/williamoliveira.png","language":"PHP","readme":"[![Travis CI Build Status](https://travis-ci.org/williamoliveira/eloquent-array-query-builder.svg?branch=master)](https://travis-ci.org/williamoliveira/eloquent-array-query-builder)\n[![Latest Stable Version](https://poser.pugx.org/williamoliveira/eloquent-array-query-builder/v/stable)](https://packagist.org/packages/williamoliveira/eloquent-array-query-builder)\n[![Total Downloads](https://poser.pugx.org/williamoliveira/eloquent-array-query-builder/downloads)](https://packagist.org/packages/williamoliveira/eloquent-array-query-builder)\n[![License](https://poser.pugx.org/williamoliveira/eloquent-array-query-builder/license)](https://packagist.org/packages/williamoliveira/eloquent-array-query-builder)\n\n## Why this nonsense?\n\nSo you can have easy to use query \"language\" to query your data, without the need to write long conditional queries by hand, very useful for REST APIs.\n\n## How to install\n\n`composer require williamoliveira/eloquent-array-query-builder`\n## How to use\n\nWe let the wiring of the request to the model to you, so you can use it wherever you want.\n\nExample in a controller:\n```php\npublic function index(Request $request, \\Williamoliveira\\ArrayQueryBuilder\\ArrayBuilder $arrayBuilder)\n{\n    $query = User::query();\n    $query = $arrayBuilder-\u003eapply($query, $request-\u003eall());\n\n    return $query-\u003epaginate($request-\u003eget('per_page')); // Note it does not do pagination or call get(),\n                                                        // you need to do it yourself\n}\n```\n\nYou can also use the ArrayQueryable trait in your model:\n```php\n // Model\n class User extends Model{\n     use \\Williamoliveira\\ArrayQueryBuilder\\Traits\\ArrayQueryable;\n // ...\n\n // Usage\n return User::arrayQuery($request-\u003eall())-\u003eget(); //static\n return (new User())-\u003enewArrayQuery($request-\u003eall())-\u003eget(); //instance\n```\n\n#### Query format\n\nHere is a example of what a query can look like:\n```php\n$exampleArrayQuery = [\n    'where' =\u003e [\n        'name' =\u003e ['like' =\u003e '%joao%'],\n        'created_at' =\u003e [\n            'between'  =\u003e [\n                 '2014-10-10',\n                 '2015-10-10',\n            ],\n        ],\n        'or' =\u003e [                             // nested boolean where clauses\n            'foo' =\u003e 'bar',\n            'baz' =\u003e 'qux',\n        ],\n    ],\n    'fields' =\u003e ['id', 'name', 'created_at'],\n    'order' =\u003e 'name',\n    'include' =\u003e [                            // relations, can have where, order and fields\n        'permissions' =\u003e true,\n        'roles' =\u003e [\n            'where' =\u003e [\n                'name' =\u003e 'admin',\n            ],\n            'fields' =\u003e ['id', 'name'],\n            'order' =\u003e 'name DESC',\n        ],\n    ],\n    'groupBy' =\u003e ['foo', 'bar', 'baz'],\n    'having' =\u003e [\n        'foo' =\u003e 'x',\n        'bar' =\u003e ['in' =\u003e ['1', '2']],\n        'baz' =\u003e ['neq' =\u003e '3'],\n    ],\n    'offset' =\u003e 5,\n    'limit' =\u003e 15,\n];\n```\n\nJust as a reference to people building REST APIs, the same query as a query string:\n```\n?where[name][like]=%joao%\n\u0026where[created_at][between][]=2014-10-10\n\u0026where[created_at][between][]=2015-10-10\n\u0026where[or][foo]=bar\n\u0026where[or][baz]=qux\n\u0026fields[]=id\n\u0026fields[]=name\n\u0026fields[]=created_at\n\u0026order=name\n\u0026include[permissions]=true\n\u0026include[roles][where][name]=admin\n\u0026include[roles][fields][]=id\n\u0026include[roles][fields][]=name\n\u0026include[roles][order]=name DESC\n\u0026groupBy[]=foo\n\u0026groupBy[]=bar\n\u0026groupBy[]=baz\n\u0026having[foo]=x\n\u0026having[bar][in][]=1\n\u0026having[bar][in][]=2\n\u0026having[baz][neq]=3\n\u0026offset=5\n\u0026limit=15\n```\nTip: for Javascript you can create a query string using [Qs](https://github.com/ljharb/qs).\n\n#### Where/Having operators aliases\n\n```\n'eq' =\u003e '=',\n'neq' =\u003e '\u003c\u003e',\n'gt' =\u003e '\u003e',\n'gte' =\u003e '\u003e=',\n'lt' =\u003e '\u003c',\n'lte' =\u003e '\u003c=',\n'nlike' =\u003e 'not like',\n'nin' =\u003e 'not in',\n'notnull' =\u003e 'not null',\n'nn' =\u003e 'not null',\n'inq' =\u003e 'in'\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamoliveira%2Feloquent-array-query-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamoliveira%2Feloquent-array-query-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamoliveira%2Feloquent-array-query-builder/lists"}