定制 technote/laravel-search-helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

technote/laravel-search-helper

最新稳定版本:v0.2.28

Composer 安装命令:

composer require technote/laravel-search-helper

包简介

Search helper for laravel

README 文档

README

CI Status codecov CodeFactor License: MIT PHP: >=7.4

Read this in other languages: English, 日本語.

Search helper for Laravel.

Packagist

Table of Contents

Details

Install

composer require technote/laravel-search-helper

Usage

  1. Implement Searchable Contract and Searchable Trait.

  2. Implement setConditions method.

    <?php
    namespace App\Models;
    
    use Eloquent;
    use Illuminate\Database\Eloquent\Builder;
    use Illuminate\Database\Eloquent\Model;
    use Technote\SearchHelper\Models\Contracts\Searchable as SearchableContract;
    use Technote\SearchHelper\Models\Traits\Searchable;
    
    /**
     * Class Item
     * @mixin Eloquent
     */
    class Item extends Model implements SearchableContract
    {
        use Searchable;
    
        /**
         * @var array
         */
        protected $guarded = [
            'id',
        ];
    
        /**
         * @param  Builder  $query
         * @param  array  $conditions
         */
        protected static function setConditions(Builder $query, array $conditions)
        {
            if (! empty($conditions['s'])) {
                collect($conditions['s'])->each(function ($search) use ($query) {
                    $query->where(function ($builder) use ($search) {
                        /** @var Builder $builder */
                        $builder->where('items.name', 'like', "%{$search}%");
                    });
                });
            }
        }
    }
  3. Call search method.

    <?php
    use App\Models\Item;
    
    Item::search([
        's' => [
            'test',
        ],
        'ids' => [1, 2, 3],
    ])->get();

Author

GitHub (Technote)
Blog

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固