{"id":18792303,"url":"https://github.com/owowagency/applies-http-query","last_synced_at":"2025-12-28T09:30:13.996Z","repository":{"id":52451163,"uuid":"196377360","full_name":"owowagency/applies-http-query","owner":"owowagency","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-18T09:43:01.000Z","size":22,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-19T21:50:10.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/owowagency.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-11T10:57:54.000Z","updated_at":"2022-12-27T14:34:25.000Z","dependencies_parsed_at":"2024-11-07T21:19:43.991Z","dependency_job_id":"06712bc7-4f5a-4764-aa99-143feba9e60c","html_url":"https://github.com/owowagency/applies-http-query","commit_stats":{"total_commits":17,"total_committers":6,"mean_commits":"2.8333333333333335","dds":0.5294117647058824,"last_synced_commit":"5eb1bf07705876308ca155e8332840017d8bb384"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owowagency%2Fapplies-http-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owowagency%2Fapplies-http-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owowagency%2Fapplies-http-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owowagency%2Fapplies-http-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owowagency","download_url":"https://codeload.github.com/owowagency/applies-http-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239718371,"owners_count":19685725,"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":[],"created_at":"2024-11-07T21:19:27.618Z","updated_at":"2025-12-28T09:30:13.954Z","avatar_url":"https://github.com/owowagency.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# owowagency/applies-http-query\n\nThis package contains a trait that can be used on Eloquent models. The trait adds a `httpQuery` scope that can apply a \"search\" and \"order by\". It will only apply these two when certain url query parameters are present.\n\n## Install\n\n```\ncomposer require owowagency/applies-http-query\n```\n\nThis package supports Laravel version 5 to 7. Check the [1.x branch](https://github.com/owowagency/applies-http-query/tree/1.x).\n\n## Usage\n\nAdd the trait to the model:\n\n```\nuse OwowAgency\\AppliesHttpQuery\\AppliesHttpQuery;\n\nclass Post extends Model\n{\n    use AppliesHttpQuery\n}\n```\n\nSpecify the columns on which it can search:\n\n```\n/**\n * Http queryable rules.\n *\n * @var array\n */\nprotected $httpQueryable = [\n    'columns' =\u003e [\n        'posts.title'\n        'users.name',\n    ],\n    'joins' =\u003e [\n        'users' =\u003e ['posts.user_id','users.id'],\n        'countries' =\u003e ['users.country_id', 'countries.id']\n    ],\n];\n```\n\nCall the scope:\n\n```\nPost::httpQuery()-\u003epaginate();\n\n// Like all other scopes it can be combined with other clauses.\nPost::whereNull('deleted_at')-\u003ehttpQuery()-\u003eget();\n```\n\nIn order for the scope to work, certain query parameters should be present in the url:\n - `search`, the value that will be searched for.\n - `order_by`, the column that will be ordered on.\n - `sort_by`, the direction of the ordering. By default this is `asc`.\n\n### Search\n\n```\nhttps://mysite.com/posts?search=test\n```\n\nWill result in the following query:\n\n```\nSELECT * FROM posts INNER JOIN users ON posts.user_id = users.id WHERE (posts.title LIKE \"%test%\" OR users.name LIKE \"%test%\")\n```\n\n### Order by\n\n\n```\nhttps://mysite.com/posts?order_by=user.name\n```\n\nWill result in the following query:\n\n```\nSELECT * FROM posts INNER JOIN users ON posts.user_id = users.id ORDER BY users.name ASC\n```\n\n```\nhttps://mysite.com/posts?order_by=user.country.name\u0026sort_by=desc\n```\n\nWill result in the following query:\n\n```\nSELECT * FROM posts INNER JOIN users ON posts.user_id = users.id INNER JOIN countries ON users.country_id = country.id ORDER BY countries.name desc\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowowagency%2Fapplies-http-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowowagency%2Fapplies-http-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowowagency%2Fapplies-http-query/lists"}