All Projects → blockpc → select2-wire

blockpc / select2-wire

Licence: MIT license
free select2 livewire for laravel

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Projects that are alternatives of or similar to select2-wire

laravel-simple-select
Laravel Simple Select inputs component for Blade and Livewire.
Stars: ✭ 59 (+227.78%)
Mutual labels:  select2, livewire, tailwindcss, alpinejs
Goodwork
Self hosted project management and collaboration tool powered by TALL stack
Stars: ✭ 1,730 (+9511.11%)
Mutual labels:  livewire, tailwindcss, alpinejs
tall-toasts
A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS 🔥🚀
Stars: ✭ 296 (+1544.44%)
Mutual labels:  livewire, tailwindcss, alpinejs
guild
Guild - Build Your Guild and award employees with Crypto 💰
Stars: ✭ 3 (-83.33%)
Mutual labels:  livewire, tailwindcss, alpinejs
YATAS
Yet Another Tailwind Alpine Starter
Stars: ✭ 18 (+0%)
Mutual labels:  tailwindcss, alpinejs
tailwind-ui-components
Free Tailwind CSS UI Components - Crafted for modern websites, landing pages and web apps. TailGrids Core is free and open-source so, feel free to use with your personal or commercial projects. If you would like to show your support and love, don't forget to give us a star 🌟
Stars: ✭ 49 (+172.22%)
Mutual labels:  tailwindcss, alpinejs
Limg
An image hosting service powered by Laravel
Stars: ✭ 41 (+127.78%)
Mutual labels:  livewire, tailwindcss
ttall
Laravel fronend preset for TTALL stack - Tailwindcss | Turbolinks | Alpine.js | Laravel | Livewire 🚀
Stars: ✭ 50 (+177.78%)
Mutual labels:  livewire, alpinejs
x-blade-components
Laravel Blade Components ready to use
Stars: ✭ 36 (+100%)
Mutual labels:  livewire, alpinejs
laravellte
Fully customizable and tests supported Laravel admin dashboard 2.0
Stars: ✭ 202 (+1022.22%)
Mutual labels:  livewire, alpinejs
craft-3
Boilerplate with Craft CMS, Tailwind CSS, VueJS & Alpine.js used for internal projects.
Stars: ✭ 34 (+88.89%)
Mutual labels:  tailwindcss, alpinejs
portfolio-2021
It is my portfolio Website.
Stars: ✭ 23 (+27.78%)
Mutual labels:  tailwindcss
kuma-gui
🐻 A GUI built on Vue.js for use with Kuma.
Stars: ✭ 34 (+88.89%)
Mutual labels:  tailwindcss
website
Personal website and blog built with Next.js, Preact, MDX, Tailwind CSS and hosted on Vercel.
Stars: ✭ 17 (-5.56%)
Mutual labels:  tailwindcss
pro-writer
Minimal yet Pro Writer 🚀
Stars: ✭ 22 (+22.22%)
Mutual labels:  tailwindcss
hue.tools
Simple toolbox for working with colors. Color mixing, blending, conversion, modification, detailed information, etc.
Stars: ✭ 331 (+1738.89%)
Mutual labels:  tailwindcss
jigsaw-docs-template
Starter template for a documentation site, using Jigsaw by Tighten
Stars: ✭ 39 (+116.67%)
Mutual labels:  tailwindcss
material-tailwind
@material-tailwind is an easy-to-use components library for Tailwind CSS and Material Design.
Stars: ✭ 861 (+4683.33%)
Mutual labels:  tailwindcss
ts-nextjs-tailwind-starter
🔋 Next.js + Tailwind CSS + TypeScript starter packed with useful development features
Stars: ✭ 880 (+4788.89%)
Mutual labels:  tailwindcss
hyperui
Free open source Tailwind CSS components 🐳
Stars: ✭ 2,443 (+13472.22%)
Mutual labels:  tailwindcss

Select2 Wire

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

    composer require blockpc/select2-wire

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

    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

    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

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

    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

    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

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

Let's 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

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

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

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

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

After this, we need a route and one controller

  • Controller: php artisan make:controller VehiclesController -i
  • Route: Route::get('/vehicle', VehiclesController::class)->name('vehicles')

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

Do you like this project? Support it by donating

Select2-Wire is open-sourced software licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].