承接 datalogix/laravel-builder-macros 相关项目开发

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

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

datalogix/laravel-builder-macros

最新稳定版本:v4.1.0

Composer 安装命令:

composer require datalogix/laravel-builder-macros

包简介

A set of useful Laravel builder macros.

README 文档

README

Latest Stable Version Total Downloads tests StyleCI codecov License

A set of useful Laravel builder macros.

Installation

You can install the package via composer:

composer require datalogix/laravel-builder-macros

The package will automatically register itself.

Macros

addSubSelect

Add a select sub query.

// Params: $column, $query
$query->addSubSelect('primary_address_id', 
    Address::select('id')
        ->where('user_id', $user->id)
        ->primary()
);

// It adds primary_address_id to the result set

defaultSelectAll

It selects all columns from the query. Useful for queries with joins and additional selects.

$query->defaultSelectAll()
    ->join('contacts', 'users.id', '=', 'contacts.user_id')
    ->addSelect('contacts.name as contact_name');

filter

Filter in your models.

$query->filter(['name' => 'john'])->get();

// Returns all results where name includes `john`

You can also supply an array of columns to filter in:

$query->filter(['name' => 'john', 'contact.email' => '@'])->get();

// Returns all results where name includes `john` or contact.email includes `@`

You can use $request->all():

$query->filter($request->all())->get();

joinRelation

A query way to join relations.

// Params: $relationName, $operator
$query->joinRelation('contact');

leftJoinRelation

A query to left join relations.

// Params: $relationName, $operator
$query->leftJoinRelation('contact');

map

A direct method to retrieve the results and map it.

$userIds = $query->where('user_id', 10)->map(function ($user) {
    return $user->id;
});

// Returns a collection

whereLike

Search in your models with the LIKE operator.

$query->whereLike('title', 'john')->get();

// Returns all results where title includes `john`
$query->whereLike('title', 'john', false)->get();

// Returns all results where title ends with `john`
$query->whereLike('title', 'john', true, false)->get();

// Returns all results where title starts with `john`

You can also supply an array of columns to search in:

$query->whereLike(['title', 'contact.name'], 'john')->get();

// Returns all results where title or contact.name includes `john`

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固