Skip to content
Advertisement

laravel sql query if and if condition

If column1 is equal to null I want my column2 to be between two dates in relation to the month and day, and if column1 is not null I want that column (column1) to be between two dates in relation to the month and day, too. All columns are of type date.

I would use this sql query in laravel with tableName->whereRaw (“SQL query”), or directly with the laravel commands if anyone knows how.

I have this for now, it works individually, but not together.

JavaScript

Advertisement

Answer

you could do it this way:

when column1 is not null get all while column1 is between …. else when column2 is not null get all while column2 is between ….

JavaScript

please not that you don’t have to format dates when using it in ‘between’

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement