PHP code example of ringlesoft / laravel-selectable

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

    

ringlesoft / laravel-selectable example snippets


    $selectableItems = \App\Models\User::all()->toSelectable()->toSelectItems();

    [
        [
            'label' => 'User Name',
            'value' => 'user_id',
            'selected' => false,
            'disabled' => false,
            'dataAttributes' => ['hidden' => false],
            'classes' => ['form-option', 'custom'],
        ],
        [...]
    ]
bladehtml
<select name="user_id">
    <option value="{{$user->id}}">{{$user->name}}</option>
    ...
</select>
bladehtml
<select name="user_id">
    <option value="{{$user->uuid}}" {{($user->uuid === '6490132934f22') ? 'selected' : '')}}>{{$user->email}}</option>
    ...
</select>