PHP code example of blockpc / select2-wire

1. Go to this page and download the library: Download blockpc/select2-wire library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blockpc / select2-wire example snippets


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);
    }
}

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);
    }
}

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);
    }
}
bash
    php artisan select2:single
bash
    php artisan select2:multiple
bash
    php artisan select2:delete
bash
    php artisan select2:single foo
bash
    php artisan select2:multiple foo