Complex DB query

Posted 1 year ago by cservices

I had to write a complex query for a project long ago. At the time it was written using Drupal. I'm trying to figure out how to write this in Laravel.

I have resorted to writing it using DB::raw(), but would really like to know how to write it using Laravel. It's go so much that I get lost when trying to group parameters.

Can someone show me how the following would be written in Laravel?

Thanks in advance for your time and your help.

$raw_sql = "SELECT * FROM projects WHERE
                            (start_ts <= $start_month) OR (start_ts BETWEEN $start_month AND $end_month)
                            (end_ts BETWEEN $start_month AND $end_month) OR (end_ts > $end_month)
                      AND (cat_id = 1)";

         $query = DB::select(DB::raw($raw_sql));

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.