定制 web-id/flan 二次开发

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

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

web-id/flan

Composer 安装命令:

composer create-project web-id/flan

包简介

FLAN - Filter Like A Ninja

README 文档

README

Installation

Require this package with composer.

composer require web-id/flan

FLAN uses Laravel Package Auto-Discovery, and doesn't require you to manually add the ServiceProvider.

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="WebId\Flan\FlanServiceProvider"

Finally, run the filter tables migration

php artisan migrate

Usage

You can create a filter with:

php artisan filter:create User

or eventually just the Filter class:

php artisan make:filter:class User

or just the Filter config:

php artisan make:filter:config User

Filter configuration

You can find the configuration files for your Filters in the folder config/FilterConfigs

A configuration file is made of two entries name and filters:

return [
    'name' => 'myfilter',
    'filters' => [
        [
            'text' => 'Model ID',
            'name' => 'id',
            'active' => true,
            'field' => [
                'type' => 'number',
            ],
        ],
        // [ ... ]
    ],
];

Configuration for any field type:

  • filters.*.text is the HTML input label
  • filters.*.name is the HTML input name attribute
  • filters.*.active determines if the data will be shown in the table
  • filters.*.filterable determines if the filter input will be shown for this column
  • filters.*.field contains options to apply on the input
  • filters.*.field.type is the input type, it can be one of those: checkbox, date, number, select, text

Configuration specific to select type:

  • filters.*.field.options contains the list of the available select options. Here an example:
'options' => [
    [
        'value' => '0',
        'text' => 'Disabled',
    ],
    [
        'value' => '1',
        'text' => 'Enabled',
    ],
    // [ ... ],
],

Filter class

The custom_select definition attribute

Let's say you are defining a BookFilter class, and you want to format the number of pages value:

$this->setDefinition('number_of_pages', [
    'custom_select' => 'CONCAT(`number_of_pages`, " pages")',
]);

The join definition attribute

Let's say you are defining a BookFilter class, and you want to be able to filter on the book's author birth city for example.

If you want to use a custom select with a join clause, in your Filter class constructor you can do this:

$this->setDefinition('author_birth_city', [
    'join' => 'leftJoinAuthorsTable',
    'custom_select' => '`authors`.`birth_city`',
]);

Then, you need to add a method named after your join parameter to apply the join on the query, in this example:

protected function leftJoinAuthorsTable(): void
{
    $this->query->leftJoin(
        'authors',
        'books.author_id',
        '=',
        'authors.id'
    );
}

Credits

License

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 9
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固