PHPackages                             thiktak/laravel-bootstrap-component-select2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. thiktak/laravel-bootstrap-component-select2

ActiveLibrary[Templating &amp; Views](/categories/templating)

thiktak/laravel-bootstrap-component-select2
===========================================

Laravel Bootstrap Blade components for Select2 &amp; Bootstrap 5.

v0.2-alpha(4y ago)010MITPHP

Since Jul 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Thiktak/laravel-bootstrap-component-select2)[ Packagist](https://packagist.org/packages/thiktak/laravel-bootstrap-component-select2)[ Docs](https://github.com/Thiktak/laravel-bootstrap-component-select2)[ RSS](/packages/thiktak-laravel-bootstrap-component-select2/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Based on the components of

Installation
------------

[](#installation)

### Run composer to install the package

[](#run-composer-to-install-the-package)

```
composer require thiktak/laravel-bootstrap-component-select2

```

### Include css

[](#include-css)

Include on your **resources/scss/app.scss** the line:

```
@import 'vendor/thiktak/laravel-bootstrap-component-select2/resources/scss/select2';
```

### Include Javascript

[](#include-javascript)

Include on your **resources/js/app.js** the line:

```
require('../../vendor/thiktak/laravel-bootstrap-component-select2/resources/js/select2');
```

### Run NPM

[](#run-npm)

```
npm run dev

```

### Use the component on your blades

[](#use-the-component-on-your-blades)

```

```

This bs::select2 component use the bs:select of . You can use all the options of this component.

Here, the important part is the `what="Model"`, with Model = App\\Models\\User or User

### Configure your models

[](#configure-your-models)

1. Implement the trait `Select2Searchable`
2. Fill the protected variable $search2Fields with list of columns to be added in the where closure
3. Implement the `__toString()` model method if you want to have a beautiful output

```
use Thiktak\LaravelBootstrapComponentSelect2\Models\Search2Proxies\Select2Searchable;

class User extends Model
{
    use Select2Searchable;

    // Will use magic search
    protected $search2Fields = ['name', 'title'];

    // [...]

}
```

You can redefine the methods `search2` and `search2_export` if required.

You can also create a proxy and build you own query. The Select2Proxy implement automatically the `Select2Searchable` trait. The proxy should be on `App\Models\Search2Proxies` folder.

```
namespace App\Models\Search2Proxies;

use Thiktak\LaravelBootstrapComponentSelect2\Models\Search2Proxies\Select2Proxy;

class UserProxy extends Select2Proxy
{
    /*
     * protected $search2Fields = ['name', 'title'];
     */

    /**
     * METHOD getModel
     *----------------
     * Define your own model
     * Used by magic method select2, if not overwritten
     */
    public function getModel() {
        return new \App\Models\User;
    }

    /**
     * Method Select2
     *----------------
     * Will return a query object based on the keyword searched
     * ... or the ID provided
     */
    public function select2($id, $term) {
        return $this->getModel()
            ->query()
            // Search by ID
            ->when($id, function($q) use($id) {
                // no return
                $q->find($id);
                // OR $q->where($this->getModel()->getPrimaryKey(), $id)
            })
            ->when(!$id, function($q) use($term) {
                return $q
                    ->where('name', 'like', '%' . $term . '%')
                    ->orderBy('name');
            });
    }

    /**
     * Method Export_select2
     * Will export array data based on Select2 format id/text
     */
    public function export_select2(User $user) {
        // id   => '1'
        // text => 'Admin (user@example.net)'
        return [
            'id'   => $user->id,
            'text' => sprintf('%s (%s)', $user->name, $user->email),
        ];
    }

    // [...]

}
```

### Test the API

[](#test-the-api)

You can test the data exported to the select by opening directly `/api/select2/search?what=User&q=a`If needed, you can use `{{ route('api.select2.search') }}`

Parameters

- `what` = the model to be used (i.e.: User or App\\Models\\User)
- `q` = search keyword

Output:

- results: \[{id: 1, text: "label"}\]
- error: { code: 200, message: null }

Use the error code to know what happens.

TODO
----

[](#todo)

- Use Proxy for Model (App\\Models\\Search2Proxies&lt;ModelName&gt;Proxy)

Changelogs
----------

[](#changelogs)

- Added select2/autoload values (fetch data via API in order to keep label synchronization)
- Added possibility to fetch by ID or by term
- Added Proxy model

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1773d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ef3483ac3589f636895ca82ee45a39a84c1561ebe648f6b500cdfe3b58a1b54?d=identicon)[Thiktak](/maintainers/Thiktak)

---

Top Contributors

[![Thiktak](https://avatars.githubusercontent.com/u/1201486?v=4)](https://github.com/Thiktak "Thiktak (11 commits)")

### Embed Badge

![Health badge](/badges/thiktak-laravel-bootstrap-component-select2/health.svg)

```
[![Health](https://phpackages.com/badges/thiktak-laravel-bootstrap-component-select2/health.svg)](https://phpackages.com/packages/thiktak-laravel-bootstrap-component-select2)
```

###  Alternatives

[cagilo/cagilo

A set of open-source Blade components for the Laravel Framework

172996.5k](/packages/cagilo-cagilo)[orchid/blade-icons

An easy way inline SVG images in your Blade templates.

223.4M9](/packages/orchid-blade-icons)[wireui/heroicons

The Tailwind Heroicons for laravel blade by WireUI

43390.8k5](/packages/wireui-heroicons)[stillat/antlers-components

2656.0k1](/packages/stillat-antlers-components)[itstructure/laravel-grid-view

Grid view for laravel framework

2546.6k2](/packages/itstructure-laravel-grid-view)[ycs77/inertia-laravel-ssr-head

Simple SSR Head for Inertia Laravel

3211.5k](/packages/ycs77-inertia-laravel-ssr-head)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
