承接 andrechalom/laravel-multiselect 相关项目开发

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

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

andrechalom/laravel-multiselect

最新稳定版本:v0.2.0

Composer 安装命令:

composer require andrechalom/laravel-multiselect

包简介

A small package for creating html select elements with multiple selections

README 文档

README

Latest Version on Packagist Software License Total Downloads

This package provides a quick interface for adding select boxes from which multiple elements may be selected. The interface is similar to the Laravel Collective HTML package, and aims to be compatible with it. However, you can use this library without Laravel Collective's HTML.

This package adheres to PSR 1, 2 and 4.

Requirements

Install

Via Composer

$ composer require andrechalom/laravel-multiselect

Service Provider & Facade

Register provider and facade on your config/app.php file. This is necessary for Laravel 5.4, but optional for >= 5.5.

'providers' => [
    ...,
    AndreChalom\LaravelMultiselect\MultiselectServiceProvider::class,
]

 'aliases' => [ 
    ...,
    'Multiselect' => AndreChalom\LaravelMultiselect\MultiselectFacade::class,
 ]

Javascript Configuration

The jQuery code required by this package is in the file multiselect.js. If you use Laravel Mix, you can include it in your mix.js. Otherwise, copy it to your public folder and source it directly in the app layout. Remember to do it after you include jQuery.

Example:

mix.js([
    'resources/assets/js/app.js',
    'vendor/andrechalom/laravel-multiselect/resources/assets/js/multiselect.js',
    ], 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

Basic Usage

(1) The default behavior creates a select element with an area where the selected options are placed. Use any key => value array to populate the select.

$list = [
    'r' => 'red',
    'g' => 'green',
    'b' => 'blue',
];

{!! Multiselect::select('colors', $list) !!}

To provide initial selected options, pass a list of keys as the third argument. All keys in this argument are supposed to be in the options list (but see "Advanced usage" below):

{!! Multiselect::select('colors', $list, ['r', 'b']) !!}

This can be populated from Eloquent models:

{!! Multiselect::select(
    'colors', 
    Colors::all()->pluck('name', 'id'), 
    isset($person) ? $person->favoriteColors()->pluck('id') : []
) !!}

(2) In the Controller, the selected options will be in a array.

public function update(Request $request, $id) {
    ...
    $this->validate(['colors' => 'array']);
    $person->favoriteColors()->sync($request->colors);
}

(3) style: the span elements generated with Multiselect are of the "multiselector" css class. You can style them as you like, for instance

.multiselector { display: inline-block; border: 1px dashed; padding: 2px; margin: 5px; cursor: pointer; }
.multiselector:after { font-family: "Glyphicons Halflings"; content: "\e014"; padding-left: 3px; }

A css file is included in this package source code, and includes the above, plus all of the elements that should be styled when using this package.

If would like to change the class or other HTML attributes of the select, option or span elements generated, use the following arguments:

{!! Multiselect::select(
    'colors', 
    $colors, 
    $default_colors,
    ['class' => 'select-class multiselect'],
    [['class' => 'option1-class', 'class' => 'option2-class']],
    ['class' => 'span-class']
) !!}

Note that the argument for options excepts an array with the same size of the $list parameter. Also note that if you change the select class, you must append "multiselect" or the Javascript code won't work.

Advanced usage

(1) A more advanced usage involves generating the select and span elements separately. To do so, use the $selectOnly argument on the select function.

{!! Multiselect::select( 'colors', $colors, $default_colors, [], [], [], true) !!}
# ... somewhere else in the page ...
{!! Multiselect::span( 'colors', $colors, $default_colors, [], false) !!}

Notice that you must pass the exact same arguments as $list and $selected for both functions.

(2) When a value passed as default to the span function is not found in the $list argument, the function generates an element with "Undefined" as label. You can change this behavior to throwing and exception using the last argument of the span function (strict mode).

(3) Unlike in LaravelCollective's select, a placeholder option is always generated. You can customize its label using

{!! Multiselect::select( 
    'colors', 
    $colors, 
    $default_colors, 
    ['placeholder' => 'Pick your favorite colors']
) !!}

(4) You can also use an autocomplete input instead of a select element! To do so, import devbridge's Autocomplete plugin, replace the calls to Multiselect::select() to Multiselect::autocomplete(), and include a Multiselect::scripts() call after jQuery is loaded.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ docker build --tag multiselect .
$ docker run -ti multiselect composer fix-style
$ docker run -ti multiselect composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email andrechalom@gmail.com instead of using the issue tracker.

Credits

The idea behind the Multiselect is based on an article by Michał Wojciechowski. This library reuses some code from Laravel Collective HTML.

License

This work is licensed under the GNU Public License. Please see License File for more information.

andrechalom/laravel-multiselect 适用场景与选型建议

andrechalom/laravel-multiselect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.4k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「form」 「multiple」 「laravel」 「select」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 andrechalom/laravel-multiselect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andrechalom/laravel-multiselect 我们能提供哪些服务?
定制开发 / 二次开发

基于 andrechalom/laravel-multiselect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2017-09-06