You would need a raw expression with a CASE statement
Jan 11, 2022
2
Level 13
Eloquent query on a created_at column
Hi. I'm working on a legacy database where I need to grab rows differently based on the date.
I.e. For anything before 2022, i need to grab the 'transaction_type' column where it contains 'DB' and then anything after the start of this year, I need to grab the 'transaction_type' column contains 'CR'
Is there a way of doing this?
I saw the ->when() function, but seems this isn't what i want as i cannot query the column with a given date.
I've not used accessors before, but would this be the way to do it, or is there a better way?
many thanks
Level 104
1 like
Please or to participate in this conversation.