定制 ravaelles/filterable 二次开发

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

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

ravaelles/filterable

Composer 安装命令:

composer require ravaelles/filterable

包简介

Package for handling record filtering in Laravel 5.*

README 文档

README

Software License

Package to handle filtering of records in Laravel 5.*, ready to work with MongoDB.

Define filters easily. Save time by using provided bootstrap view which displays all the filters and properly styles select elements (and far more!). Oh, and there's also a nice search box, too! :)

Install

Via Composer

$ composer require ravaelles/filterable

Usage

(1)   Open config/app.php and add to the end of providers this entry:

\Ravaelles\Filterable\FilterableServiceProvider::class,

(2)   Now open command line in root of your project and publish a view:

php artisan vendor:publish

Feel free to modify it, it's now in resources\views\packages\filterable\filtering.blade.php

(3)   Notice that filtering.blade.php uses @push('scripts') operator. It appends all the javascript scripts to the end of the html, when jQuery has already been loaded to avoid jQuery is not defined error. To make it work, please add @stack('scripts') part just after you load your last script using <script> tag. Notice the @stack blade operator is available since about Laravel 5.2.20.

(4)   Now in your model add this trait:

use Ravaelles\Filterable\Filterable as Filterable;
(..)
class MyModelName extends Model 
{
    use Filterable; // Add trait

Every model that you want to be filterable will need this trait.

(5)   It's time to define filters to be used (variable $filters). We will define some example filters so you can see how it works. In your controller, just where you retrieve the records, add this:

$filters = [

    // First filter
    'status' => [ // Db field name
        'Status' => [ // Field name to be shown for user
            1 => "Created", // [Values => Display names] for select element
            2 => "Awaiting signature",
            3 => "Canceled",
            4 => "Signed",
        ]
    ],
    
    // Second filter
    'template_id' => [
        'Template' => [0 => "No", 1 => "Yes"]
        // 'Template' => Template::orderBy('id', -1)->pluck('name', 'id')->all() // Or use something like this
    ],
    
    // You can add more filters here
    //'field_name' => [
    //     'Display name' => ["black" => "Black tea", "green" => "Green tea"]
    //],
];

$users = User::orderBy('id')
	->filterable($filters)
	->paginate(10);

Notice that you can apply your own, custom where clauses just before the ->filterable part.

(6)   Finally, in your view add this line which will automatically display the filters using selects:

@include('vendor.filterable.filtering')

Feel free to modify this file as you wish.

(7)   If you wish to use search box functionality then make sure to add ->searchable() line in your controller like this:

$users = User::orderBy('id')
    ->searchable()
	->filterable($filters)
	->paginate(10);

...and in your model add a list of fields you want to search against e.g.

public $searchable = [
    'name', 'email', 'address'
];

It will search for text from the search box in any of these fields.

(8)   You are now able to use this package and dynamically filter the records! :)

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固