PHP code example of salioudiabate / select

1. Go to this page and download the library: Download salioudiabate/select 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/ */

    

salioudiabate / select example snippets


class EditPost extends Component
{
    public ?int $authorId = null;

    public function searchAuthors(string $query): array
    {
        return User::query()
            ->where('name', 'like', "%{$query}%")
            ->limit(20)
            ->get(['id', 'name'])
            ->map(fn ($user) => ['value' => $user->id, 'label' => $user->name])
            ->all();
    }

    public function render(): View
    {
        return view('livewire.edit-post', [
            'author' => $this->authorId ? User::find($this->authorId) : null,
        ]);
    }
}

$countries = [
    ['value' => 'fr', 'label' => 'France', 'region' => 'Europe'],
    ['value' => 'ci', 'label' => 'Ivory Coast', 'region' => 'Africa'],
    // ...
];

public function createTag(string $label): array
{
    $tag = Tag::create(['name' => $label]);

    return ['value' => $tag->id, 'label' => $tag->name];
}

class EditPost extends Component
{
    #[Validate('nction save(): void { $this->validate(); /* ... */ }
}

use Livewire\Livewire;

Livewire::test(EditPost::class)
    ->set('authorId', $user->id)
    ->assertSet('authorId', $user->id);

Livewire::test(EditPost::class)
    ->call('searchAuthors', 'jane')
    ->assertReturned(fn ($results) => collect($results)->pluck('label')->contains('Jane Doe'));
bash
php artisan vendor:publish --tag=select-assets
bash
php artisan vendor:publish --tag=select-config
js
Select.setColorScheme('dark'); // 'light' | 'dark' | 'system'
js
function setSiteColorScheme(scheme) {
    if (window.Notify) Notify.setColorScheme(scheme);
    if (window.Modal) Modal.setColorScheme(scheme);
    if (window.Select) Select.setColorScheme(scheme);
}
bash
php artisan vendor:publish --tag=select-views