fergardi/select2-bundle
A Symfony bundle that integrates Select2 into your forms, giving you searchable, AJAX-powered select boxes with minimal setup. Includes reusable form types and asset wiring so dropdowns can load remote data quickly and consistently.
First, calibrate expectations: fergardi/select2-bundle is a Symfony bundle, not a Laravel package. It exists to ship Select2's JS/CSS as bundle resources so Symfony apps can include them via the asset pipeline instead of a CDN. It has no Laravel service provider, no auto-discovery, and no facades. As a Laravel developer, treat it as an asset source you can borrow from — not something you composer require and expect to boot.
Minimal steps to evaluate it:
composer.json on the repo: confirm the type (symfony-bundle), the require block (likely symfony/framework-bundle plus a pinned Select2 version), and the Resources/public/ (or Resources/assets/) layout.config/bundles.php, run php bin/console assets:install --symlink, then include bundles/<bundlename>/js/select2.min.js and the matching CSS in your base template.npm install select2 (or pull the two files from the repo's Resources/public) and publish them to public/vendor/select2.Look first at the bundle's Resources/ tree and any Twig extension/helper it registers — that's where the actual value is. The first real use case is simple: a <select> enhanced with search, multi-select, or AJAX-loaded options without hand-managing vendor files. Given 0 stars and 0 dependents, verify the bundled Select2 version before adopting.
Symfony-native pattern (what the bundle intends):
base.html.twig:
<link rel="stylesheet" href="{{ asset('bundles/fergardiselect2/css/select2.min.css') }}">
<script src="{{ asset('bundles/fergardiselect2/js/select2.min.js') }}"></script>
$('.js-select2').select2({ placeholder: '...', allowClear: true }).js-select2) rather than binding to every <select>, so you can opt in per field.Laravel adaptation pattern (the realistic day-to-day path):
public/vendor/select2/, or install via npm and let Vite bundle them.{{-- resources/views/components/select2.blade.php --}}
<select {{ $attributes->merge(['class' => 'js-select2']) }}>{{ $slot }}</select>
resources/js/app.js and re-init after Livewire/DOM swaps (Livewire.hook('morph.updated', ...)).ajax.url at a Laravel route returning { results: [{ id, text }] } — Select2's expected shape — and use processResults if your payload differs.Integration tips: keep Select2 and jQuery versions pinned together; load CSS before JS; scope initialization to forms that need it rather than globally, to avoid clashing with other select widgets.
composer require gets you files, not a working integration. Budget for vendoring or npm.bundles/<name>/... URLs only resolve after assets:install (or with a symlink in dev). A 404 on select2.min.js is almost always a missed install step — check the network tab first.select2 is not a function. Nearly always jQuery loaded twice, loaded after Select2, or a Vite bundle ordering issue. Ensure a single jQuery instance is global before the plugin runs.hidden vs select2-hidden-accessible, different event names). Check what's actually shipped; don't assume v4 behavior..select2-container, (4) verify select2:select / change events fire for your form logic.initSelect2(el) JS helper is the clean seam. Keep initialization idempotent (if (!$(el).data('select2')) ...) so re-renders don't stack widgets.How can I help you explore Laravel packages today?