Skip to content
Advertisement

Array variable inside DB::raw query laravel

I want to predifine $processingStatus array and use it inside Laravel DB::raw query but this gives me the following error-

Syntax error or access violation: 1064 You have an error in your SQL syntax

My query is a large one so I am only pasting the fragment which I guess is causing the error-

DB::raw("COUNT(CASE WHEN (status_change_log.status in $processingStatus) THEN 1 END) AS processing")

My processingStatus variable contains [0 => “S2”, 1 => “S13”, 2 => “S21”]

Anyone help me out with proper format?

Advertisement

Answer

Concatenate the string with the php variable

DB::raw("COUNT(CASE WHEN (status_change_log.status in ".$processingStatus.") THEN 1 END) AS processing")
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement