{"id":15199876,"url":"https://github.com/blockpc/select2-wire","last_synced_at":"2025-08-22T00:31:36.337Z","repository":{"id":41102789,"uuid":"447009824","full_name":"blockpc/select2-wire","owner":"blockpc","description":"free select2 livewire for laravel","archived":false,"fork":false,"pushed_at":"2024-09-22T03:38:24.000Z","size":123,"stargazers_count":25,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-15T06:09:30.432Z","etag":null,"topics":["alpinejs","laravel","livewire","php","select2","tailwindcss"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blockpc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-01-11T23:12:29.000Z","updated_at":"2024-09-22T03:38:27.000Z","dependencies_parsed_at":"2024-03-16T18:11:05.874Z","dependency_job_id":null,"html_url":"https://github.com/blockpc/select2-wire","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"56517b0aa65342b6468b76102dc03d163bda00ce"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockpc%2Fselect2-wire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockpc%2Fselect2-wire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockpc%2Fselect2-wire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockpc%2Fselect2-wire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blockpc","download_url":"https://codeload.github.com/blockpc/select2-wire/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542288,"owners_count":18242332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpinejs","laravel","livewire","php","select2","tailwindcss"],"created_at":"2024-09-28T02:05:26.470Z","updated_at":"2024-12-20T06:06:49.837Z","avatar_url":"https://github.com/blockpc.png","language":"PHP","funding_links":["https://paypal.me/blockpc"],"categories":[],"sub_categories":[],"readme":"# Select2 Wire\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://blockpc.cl\" target=\"_blank\"\u003e\u003cimg src=\"https://banners.beyondco.de/Select2%20Wire.png?theme=light\u0026packageManager=composer+require\u0026packageName=blockpc%2Fselect2-wire\u0026pattern=architect\u0026style=style_1\u0026description=Select2+livewire+component\u0026md=1\u0026showWatermark=1\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## read plis\n\nThis package is old... i found that create a select2 for laravel its very simple, checkout this git https://gist.github.com/blockpc/5878e8d02b1fa33a9e13ab912e9a6440\nnow the gist is old version, but how to explain depends each one, the basic is the same\n\n## old version\n\nThis package create a select2 livewire component via commands.\nThe package is built under a TALL stack. Make sure you have the requirements (see composer.json)\nOne 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.\n\n## Installation\n\n```bash\n    composer require blockpc/select2-wire\n```\n\n## Commands\n\n\u003e **Single component**\nCreate a component that works as a single selectable, allows you to add data on the fly\n\n```bash\n    php artisan select2:single\n```\n\n\u003e **Multiple component**\nCreate a component that works as a multiple selectable, allows you to add data on the fly, data must be separated by commas\n\n```bash\n    php artisan select2:multiple\n```\n\n\u003e **Delete component**\nThis commando delete a component created \n\n```bash\n    php artisan select2:delete\n```\n\n### Single Component Foo\n\n```bash\n    php artisan select2:single foo\n```\n\nThis 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.\n\n### Single Component Foo with model Baz\n\n```bash\n    php artisan select2:single foo --model=baz\n    # or\n    php artisan select2:single foo -m baz\n```\n\nThis 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.\n\n### Single Component Foo with model Baz and parent model Taz\n\nThis 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.\n\n```bash\n    php artisan select2:single foo --model=baz --parent=taz\n    # or\n    php artisan select2:single foo -m baz -p taz\n```\n\nThis 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`)\n\n### Multiple Component Foo\n\n```bash\n    php artisan select2:multiple foo\n```\n\nThis 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.\n\n### Multiple Component Foo with model Baz\n\n```bash\n    php artisan select2:multiple foo --model=baz\n    # or\n    php artisan select2:multiple foo -m baz\n```\n\nThis 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.\n\n### Multiple Component Foo with model Baz and parent model Taz\n\nThis 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.\n\n```bash\n    php artisan select2:multiple foo --model=baz --parent=taz\n    # or\n    php artisan select2:multiple foo -m baz -p taz\n```\n\nThis 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`)\n\n## Usage\n\n### Let's suppose\n\u003e Our company sells vehicles and each vehicle has one code, a brand and can be in various colors.\n\nFrom 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.\n\n_In the example directory you find all files you needs for this tutorial_\n\n### Brand\nThe model `brand` have a relation one-to-one with parent model `vehicle`  \n`One vehicle has one brand`  \nThis relation we called like `single` relation\n\n### Colors\nThe model `color` have a relation many-to-many with parent model `vehicle` \n`One vehicle has many colors and one color can be set in many vehicles`  \nThis relation we called like `multiple` relation  \n\n### Extra Migration\nFor a `multiple` relation we need a migration that creates the table that contains the foreign keys for `color` and `vehicle` models\n`php artisan make:migration create_color_vehicle_table`\n\n_you find all the migrations in example directory_\n\n**run mingrations**\n\n### Models\nSo, your parent model `vehicle` should look like this  \n\n```php\nclass Vehicle extends Model\n{\n    // ... \n    protected $fillable = ['code'];\n\n    // one-to-one brand\n    public function brand(): BelongsTo\n    {\n        return $this-\u003ebelongsTo(Brand::class);\n    }\n\n    // many-to-many colors\n    public function colors(): BelongsToMany // Dont forget import this class\n    {\n        return $this-\u003ebelongsToMany(Color::class);\n    }\n}\n```\n\nYour `single relation brand` should look like this:\n\n```php\nclass Brand extends Model\n{\n    // ...\n    protected $fillable = ['name'];\n\n    // one-to-many vehicles \n    public function vehicles(): HasMany // Dont forget import this class\n    {\n        return $this-\u003ehasMany(Vehicle::class);\n    }\n}\n```\n\nYour `multiple relation colors` should look like this:\n\n```php\nclass Color extends Model\n{\n    // ...\n    protected $fillable = ['name'];\n\n    // One color has many vehicle\n    public function vehicles(): BelongsToMany // Dont forget import this class\n    {\n        return $this-\u003ebelongsToMany(Vehicle::class);\n    }\n}\n```\n\n### Route and Controller\nAfter this, we need a route and one controller\n\n- Controller: `php artisan make:controller VehiclesController -i`\n- Route: _Route::get('/vehicle', VehiclesController::class)-\u003ename('vehicles')_\n\n### Commands needed\nWe run two commands\n\n- php artisan select2:single brand -p vehicle\n- php artisan select2:multiple color -p vehicle\n\nAnd 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.\n\n**enjoy**\n\n\n## 💖 Support the development\n**Do you like this project? Support it by donating**\n\n- PayPal: [Donate](https://paypal.me/blockpc)\n\nSelect2-Wire is open-sourced software licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockpc%2Fselect2-wire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblockpc%2Fselect2-wire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockpc%2Fselect2-wire/lists"}