yneet / laravel-collection-select2
一套用于Select2的有用Laravel集合宏
1.0
2020-08-24 09:35 UTC
Requires
- php: ^7.4
- illuminate/support: ^7.0
This package is not auto-updated.
Last update: 2024-09-25 13:54:18 UTC
README
此存储库包含一些有用的Select2集合宏。
安装
您可以通过composer引入此包
composer require yneet/laravel-collection-select2
该包将自动注册自身
宏
toSelect2Grouped
将集合直接转换为Select2 Ajax/Data格式分组(见:https://select2.org/data-sources/formats#grouped-data)。
$collection = collect([ ['text' => 'Title 1', 'id' => 1, 'group' => 'Group 1'], ['text' => 'Title 2', 'id' => 2, 'group' => 'Group 1'], ... ]); $collection->toSelect2Grouped('group'); // [ // [ // 'text' => 'Group 1', // 'children' => [ // ['text' => 'Title 1', 'id' => 1, 'group' => 'Group 1'], // ['text' => 'Title 2', 'id' => 2, 'group' => 'Group 1'] // ] // ], // ... // ];
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。