angauber/nova-select2-filter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

angauber/nova-select2-filter

最新稳定版本:v1.1.0

Composer 安装命令:

composer require angauber/nova-select2-filter

包简介

A Laravel Nova filter.

README 文档

README

This repository is not maintained anymore

nova-select2-filter

Works with both solo and multi select

multi

Instalation

composer require angauber/nova-select2-filter

Usage

Create a new filter with

php artisan nova:filter MyNewFilter

Then replace it's content like so

<?php namespace App\Nova\Filters; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Angauber\NovaSelect2Filter\NovaSelect2Filter; class ContactType extends NovaSelect2Filter { public $component = 'nova-select2-filter'; public function apply(Request $request, $query, $value) { return $query; } public function options(Request $request) { return []; } public function config() { return [ 'multiple' => true, 'allowClear' => true, 'placeholder' => 'Choose option(s)', ]; } } 

The $value parameter of the apply() method will either be an array of string or a string depending if multiple is set to true or false in the config method

The option() method must return an array of key => value

The config() method must return an array containing select2 config parameters. See Select2 documentaion

Example

Let's say you want to implement a multiple selection to filter a User Model on a Many relationship, you could do like so

 <?php namespace App\Nova\Filters; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Angauber\NovaSelect2Filter\NovaSelect2Filter; use \App\Models\UserType; class ContactType extends NovaSelect2Filter { public $component = 'nova-select2-filter' public function apply(Request $request, $query, $value) { return $query->whereHas('type', function(Builder $query) use ($value) { $query->whereIn('types.id', $value) }); } public function options(Request $request) { return UserType::pluck('name', 'id'); } public function config(): array { return [ 'multiple' => true, 'allowClear' => true, 'placeholder' => 'Choose option(s)', ]; } } 

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固