F
Filamentβ€’9mo ago
GavTheDev

Only one primary row when toggled in table

I'm looking to add a toggle or radio to a table (not in panel) that allows only one value to be selected. If another value is toggled, that one becomes primary and the other ones are deselected. I'm pretty sure I've seen it somewhere but now I cannot find it πŸ˜•
3 Replies
LeandroFerreira
LeandroFerreiraβ€’9mo ago
You could use an Observer https://laravel.com/docs/11.x/eloquent#observers
public function updated(YorModel $model): void
{
if ($model->wasChanged('field')) {
YorModel::where('id', '!=', $model->id)
->update(['field' => false]);
}
}
public function updated(YorModel $model): void
{
if ($model->wasChanged('field')) {
YorModel::where('id', '!=', $model->id)
->update(['field' => false]);
}
}
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation β€” freeing you to create without sweating the small things.
GavTheDev
GavTheDevOPβ€’9mo ago
Thanks, that is an option indeed. But in this case I'm specically looking for that option that I know I have seen somewhere. Perhaps it was a plugin?
awcodes
awcodesβ€’9mo ago
I think an observer is the proper place to do this.
Want results from more Discord servers?
Add your server