PHPackages                             blockpc/select2-wire - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. blockpc/select2-wire

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

blockpc/select2-wire
====================

Free Select2 Livewire package

v1.1.1(4y ago)251.2kMITPHP

Since Jan 18Pushed 1y ago4 watchersCompare

[ Source](https://github.com/blockpc/select2-wire)[ Packagist](https://packagist.org/packages/blockpc/select2-wire)[ RSS](/packages/blockpc-select2-wire/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (5)Used By (0)

Select2 Wire
============

[](#select2-wire)

[![](https://camo.githubusercontent.com/54212c86e3c5e728f4faa9cde6d2864ded45f9199d89c64a1d6786d5db2dc5f3/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f53656c65637432253230576972652e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d626c6f636b706325324673656c656374322d77697265267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d53656c656374322b6c697665776972652b636f6d706f6e656e74266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://blockpc.cl)

read plis
---------

[](#read-plis)

This package is old... i found that create a select2 for laravel its very simple, checkout this git now the gist is old version, but how to explain depends each one, the basic is the same

old version
-----------

[](#old-version)

This package create a select2 livewire component via commands. The package is built under a TALL stack. Make sure you have the requirements (see composer.json) One command creates a livewire component as well as its view, plus it gives you the option to create a trait to receive basic events on a parent component.

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

[](#installation)

```
    composer require blockpc/select2-wire
```

Commands
--------

[](#commands)

> **Single component**Create a component that works as a single selectable, allows you to add data on the fly

```
    php artisan select2:single
```

> **Multiple component**Create a component that works as a multiple selectable, allows you to add data on the fly, data must be separated by commas

```
    php artisan select2:multiple
```

> **Delete component**This commando delete a component created

```
    php artisan select2:delete
```

### Single Component Foo

[](#single-component-foo)

```
    php artisan select2:single foo
```

This command create a `single` component select2 class (under directory app `Livewire/Select2/FooSelect2.php`) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Foo` related.

### Single Component Foo with model Baz

[](#single-component-foo-with-model-baz)

```
    php artisan select2:single foo --model=baz
    # or
    php artisan select2:single foo -m baz
```

This command create a `single` component select2 class (under directory app `Livewire/Select2/FooSelect2.php`) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Baz` related.

### Single Component Foo with model Baz and parent model Taz

[](#single-component-foo-with-model-baz-and-parent-model-taz)

This is the suggested command. It has the same behavior as the others but adds some events (and listeners) that allow you to interact with a foreign component (ex CRUD). It also allows you to create a trait to help you in this.

```
    php artisan select2:single foo --model=baz --parent=taz
    # or
    php artisan select2:single foo -m baz -p taz
```

This command create a `single` component select2 class (under directory app `Livewire/Select2/FooSelect2.php`) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Baz` related and parent model `Taz`, Gives you the option to create a trait if you need to interact with an external component (under directory app `Livewire/Select2/Traits/SingleSelect2.php`)

### Multiple Component Foo

[](#multiple-component-foo)

```
    php artisan select2:multiple foo
```

This command create a `multiple` component select2 class (under `Livewire/Select2/FooSelect2.php` directory app) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Foo` related.

### Multiple Component Foo with model Baz

[](#multiple-component-foo-with-model-baz)

```
    php artisan select2:multiple foo --model=baz
    # or
    php artisan select2:multiple foo -m baz
```

This command create a `multiple` component select2 class (under directory app `Livewire/Select2/FooSelect2.php`) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Baz` related.

### Multiple Component Foo with model Baz and parent model Taz

[](#multiple-component-foo-with-model-baz-and-parent-model-taz)

This is the suggested command. It has the same behavior as the others but adds some events (and listeners) that allow you to interact with a foreign component (ex CRUD). It also allows you to create a trait to help you in this.

```
    php artisan select2:multiple foo --model=baz --parent=taz
    # or
    php artisan select2:multiple foo -m baz -p taz
```

This command create a `multiple` component select2 class (under directory app `Livewire/Select2/FooSelect2.php`) and one view (under directory resource `livewire/select2/foo-select2.blade.php`) with a model `Baz` related and parent model `Taz`, Gives you the option to create a trait if you need to interact with an external component (under directory app `Livewire/Select2/Traits/MultipleSelect2.php`)

Usage
-----

[](#usage)

### Let's suppose

[](#lets-suppose)

> Our company sells vehicles and each vehicle has one code, a brand and can be in various colors.

From what has been read above we understand that we have a **parent model** called `vehicle`. And each one has properties like one name, one brand and could be has many colors.

*In the example directory you find all files you needs for this tutorial*

### Brand

[](#brand)

The model `brand` have a relation one-to-one with parent model `vehicle`
`One vehicle has one brand`
This relation we called like `single` relation

### Colors

[](#colors)

The model `color` have a relation many-to-many with parent model `vehicle``One vehicle has many colors and one color can be set in many vehicles`
This relation we called like `multiple` relation

### Extra Migration

[](#extra-migration)

For a `multiple` relation we need a migration that creates the table that contains the foreign keys for `color` and `vehicle` models `php artisan make:migration create_color_vehicle_table`

*you find all the migrations in example directory*

**run mingrations**

### Models

[](#models)

So, your parent model `vehicle` should look like this

```
class Vehicle extends Model
{
    // ...
    protected $fillable = ['code'];

    // one-to-one brand
    public function brand(): BelongsTo
    {
        return $this->belongsTo(Brand::class);
    }

    // many-to-many colors
    public function colors(): BelongsToMany // Dont forget import this class
    {
        return $this->belongsToMany(Color::class);
    }
}
```

Your `single relation brand` should look like this:

```
class Brand extends Model
{
    // ...
    protected $fillable = ['name'];

    // one-to-many vehicles
    public function vehicles(): HasMany // Dont forget import this class
    {
        return $this->hasMany(Vehicle::class);
    }
}
```

Your `multiple relation colors` should look like this:

```
class Color extends Model
{
    // ...
    protected $fillable = ['name'];

    // One color has many vehicle
    public function vehicles(): BelongsToMany // Dont forget import this class
    {
        return $this->belongsToMany(Vehicle::class);
    }
}
```

### Route and Controller

[](#route-and-controller)

After this, we need a route and one controller

- Controller: `php artisan make:controller VehiclesController -i`
- Route: *Route::get('/vehicle', VehiclesController::class)-&gt;name('vehicles')*

### Commands needed

[](#commands-needed)

We run two commands

- php artisan select2:single brand -p vehicle
- php artisan select2:multiple color -p vehicle

And we make sure to accept the creation of the traits. Then we add the components we created to use in the controller view. you can see the example and how it was structured.

**enjoy**

💖 Support the development
-------------------------

[](#-support-the-development)

**Do you like this project? Support it by donating**

- PayPal: [Donate](https://paypal.me/blockpc)

Select2-Wire is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% 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 ~1 days

Total

3

Last Release

1579d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61f2c2563027328b7590a32234f2eae2246ed6eac5f214d5f423a56f0c70c6c2?d=identicon)[blockpc](/maintainers/blockpc)

---

Top Contributors

[![chunchillo](https://avatars.githubusercontent.com/u/20343085?v=4)](https://github.com/chunchillo "chunchillo (22 commits)")[![blockpc](https://avatars.githubusercontent.com/u/71981817?v=4)](https://github.com/blockpc "blockpc (2 commits)")

---

Tags

alpinejslaravellivewirephpselect2tailwindcss

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/blockpc-select2-wire/health.svg)

```
[![Health](https://phpackages.com/badges/blockpc-select2-wire/health.svg)](https://phpackages.com/packages/blockpc-select2-wire)
```

###  Alternatives

[livewire/flux

The official UI component library for Livewire.

9475.0M86](/packages/livewire-flux)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[jantinnerezo/livewire-alert

This package provides a simple alert utilities for your livewire components.

8041.2M20](/packages/jantinnerezo-livewire-alert)[leandrocfe/filament-apex-charts

Apex Charts integration for Filament PHP.

4861.2M8](/packages/leandrocfe-filament-apex-charts)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-dashboard

A dashboard for Laravel

568156.1k94](/packages/spatie-laravel-dashboard)

PHPackages © 2026

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