Multiple Select Issue
Select::make('pos_devices_id')
->label('POS Devices')
->default(function () {
$userId = auth()->user()->id;
return PosDevice::whereHas('users', function ($query) use ($userId) {
$query->where('users.id', $userId);
})->pluck('name','id')->toArray();
})
->options(function (Get $get, Set $set) {
$userId = $get('user_id');
$test = PosDevice::doesntHave('users', 'and', function ($query) use ($userId) {
$query->where('user_id', $userId);
})->where('status', 1)->pluck('name', 'id')->toArray();
// $set('data', $test);
if ($userId) {
return $test;
}
return [];
})
->multiple()
->live()
->afterStateUpdated(function (Get $get, $state) {
$assignDevices = $get('Assigned Devices');
info($state);
return $state;
}),
Select::make('pos_devices_id')
->label('POS Devices')
->default(function () {
$userId = auth()->user()->id;
return PosDevice::whereHas('users', function ($query) use ($userId) {
$query->where('users.id', $userId);
})->pluck('name','id')->toArray();
})
->options(function (Get $get, Set $set) {
$userId = $get('user_id');
$test = PosDevice::doesntHave('users', 'and', function ($query) use ($userId) {
$query->where('user_id', $userId);
})->where('status', 1)->pluck('name', 'id')->toArray();
// $set('data', $test);
if ($userId) {
return $test;
}
return [];
})
->multiple()
->live()
->afterStateUpdated(function (Get $get, $state) {
$assignDevices = $get('Assigned Devices');
info($state);
return $state;
}),
->default(function () {
$userId = auth()->user()->id;
return PosDevice::whereHas('users', function ($query) use ($userId) {
$query->where('users.id', $userId);
})->pluck('id')->toArray();
})
->default(function () {
$userId = auth()->user()->id;
return PosDevice::whereHas('users', function ($query) use ($userId) {
$query->where('users.id', $userId);
})->pluck('id')->toArray();
})
1 Reply
pos_devices_id
should be a json column
https://filamentphp.com/docs/3.x/forms/fields/select#multi-select