disabled select option multiple value base on status from db
I have Select Option Its Disabled Option value when status by id is sold
Select::make('batch_id')
->required()
->relationship('batch_faktur_pajak', 'batch')
->options(BatchFakturPajak::all()->pluck('batch', 'id'))
->live(debounce: 1500)
->disableOptionWhen(function ($value) {
$get_status = BatchFakturPajak::where('status', '=', 'sold')->get();
foreach ($get_status as $status) {
if ($status->id == $value) {
return true;
} else {
return false;
}
}
})
i have 10 and 20 value bot sold status
but On Select It Disabled Only 10
i know because it return bool but i dkw how to fix that


8 Replies
Sth like this, but not tested

Yeah I didn't test π Anyway why don't you query only (! sold) in relationship like this
Then you can remove
options()
and disableOptionWhen()
ya this will work
but i wanna to see history batch value
solved btw with u suggest and little modification
->disableOptionWhen(function (int $value) {
$get_status = BatchFakturPajak::where('status', 'sold')->get('id')->toArray();
return collect($get_status)
->contains(function (array $val, int $key) use ($value) {
return $val['id'] == $value;
});
})

thx u bro
π
You're welcome. btw you can reduce your code like this
damn that cool
thx u bro π