How to insert data in TextColumn using CASE query

How can I assign a value using a CASE query in a TextColumn::make() column in Filament, considering that the value depends on conditions in the model X? This is the query
DB::raw('
CASE
WHEN bookings.user_id IS NULL AND bookings.br_company_id IS NULL THEN 1
WHEN bookings.user_id IS NOT NULL THEN 2
WHEN bookings.br_company_id IS NOT NULL THEN 3
END as client_type
')
DB::raw('
CASE
WHEN bookings.user_id IS NULL AND bookings.br_company_id IS NULL THEN 1
WHEN bookings.user_id IS NOT NULL THEN 2
WHEN bookings.br_company_id IS NOT NULL THEN 3
END as client_type
')
I'm not sure what value to put inside the TextColumn::make() since it wouldn't involve a direct relationship. Ty for all.
2 Replies
Dennis Koch
Dennis Koch14mo ago
You could extend the table query (->query()) and add this raw statement. Then access it via the text column If this doesn’t need to happen on DB level you could just calculate the value via getStateUsing()
Juan Haag
Juan HaagOP14mo ago
Thx!!
Want results from more Discord servers?
Add your server