承接 owowagency/applies-http-query 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

owowagency/applies-http-query

最新稳定版本:v3.0.0

Composer 安装命令:

composer require owowagency/applies-http-query

包简介

README 文档

README

This 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.

Install

composer require owowagency/applies-http-query

This package supports Laravel version 5 to 7. Check the 1.x branch.

Usage

Add the trait to the model:

use OwowAgency\AppliesHttpQuery\AppliesHttpQuery;

class Post extends Model
{
    use AppliesHttpQuery
}

Specify the columns on which it can search:

/**
 * Http queryable rules.
 *
 * @var array
 */
protected $httpQueryable = [
    'columns' => [
        'posts.title'
        'users.name',
    ],
    'joins' => [
        'users' => ['posts.user_id','users.id'],
        'countries' => ['users.country_id', 'countries.id']
    ],
];

Call the scope:

Post::httpQuery()->paginate();

// Like all other scopes it can be combined with other clauses.
Post::whereNull('deleted_at')->httpQuery()->get();

In order for the scope to work, certain query parameters should be present in the url:

  • search, the value that will be searched for.
  • order_by, the column that will be ordered on.
  • sort_by, the direction of the ordering. By default this is asc.

Search

https://mysite.com/posts?search=test

Will result in the following query:

SELECT * FROM posts INNER JOIN users ON posts.user_id = users.id WHERE (posts.title LIKE "%test%" OR users.name LIKE "%test%")

Order by

https://mysite.com/posts?order_by=user.name

Will result in the following query:

SELECT * FROM posts INNER JOIN users ON posts.user_id = users.id ORDER BY users.name ASC
https://mysite.com/posts?order_by=user.country.name&sort_by=desc

Will result in the following query:

SELECT * 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

统计信息

  • 总下载量: 7.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-07-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固