PHP code example of alenadashko / filament-dropdown-checkbox-list
1. Go to this page and download the library: Download alenadashko/filament-dropdown-checkbox-list 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/ */
alenadashko / filament-dropdown-checkbox-list example snippets
use AlenaDashko\DropdownCheckboxList\Components\DropdownCheckboxList;
DropdownCheckboxList::make('tags')
->options(Tag::pluck('name', 'id'))
DropdownCheckboxList::make('products')
->searchUsing(fn (string $search) => Product::where('name', 'like', "%{$search}%")
->limit(50)
->pluck('name', 'id')
->toArray()
)
->selectedOptionLabelsUsing(fn (array $values) => Product::whereIn('id', $values)
->pluck('name', 'id')
->toArray()
)
DropdownCheckboxList::make('permissions')
->groupedOptions([
'Users' => [
'users.view' => 'View users',
'users.create' => 'Create users',
'users.delete' => 'Delete users',
],
'Posts' => [
'posts.view' => 'View posts',
'posts.create' => 'Create posts',
],
])
DropdownCheckboxList::make('categories')
->groupedOptions([
'Goods' => [
'Electronics' => [
'phones' => 'Phones',
'laptops' => 'Laptops',
],
'Clothing' => [
'shirts' => 'Shirts',
'shoes' => 'Shoes',
],
],
'Services' => [
'Repair' => [
'car-repair' => 'Car repair',
'phone-repair' => 'Phone repair',
],
],
])
DropdownCheckboxList::make('permissions')
->groupedOptions([...])
->collapseGroupsByDefault()
DropdownCheckboxList::make('permissions')
->searchGroupedOptionsUsing(fn (string $search) => Permission::query()
->when($search, fn ($q) => $q->where('label', 'like', "%{$search}%"))
->get()
->groupBy('group')
->map(fn ($items) => $items->pluck('label', 'id')->all())
->all()
)
->selectedOptionLabelsUsing(fn (array $values) => Permission::whereIn('id', $values)
->pluck('label', 'id')
->toArray()
)
use AlenaDashko\DropdownCheckboxList\Components\DropdownCheckboxList;
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
Filter::make('subdepartments')
->form([
DropdownCheckboxList::make('subdepartments')
->live()
->groupedOptions(/* ... */)
->searchable(),
])
->query(fn (Builder $query, array $data): Builder => $query->when(
$data['subdepartments'] ?? null,
fn (Builder $query, $value): Builder => $query->whereIn('subdepartment', $value),
))
DropdownCheckboxList::make('categories')
->options(Category::pluck('name', 'id'))
->optionsLimit(100)
use AlenaDashko\DropdownCheckboxList\Concerns\HasDropdownSearch;
class MyListResource extends Component
{
use HasDropdownSearch;
}
return [
'placeholder' => 'Select...',
'selected_count' => 'selected',
'no_results' => 'No results found',
'select_all' => 'Select all',
'deselect_all' => 'Deselect all',
];
bash
php artisan vendor:publish --tag=dropdown-checkbox-list-views
lang/vendor/dropdown-checkbox-list/{locale}/messages.php