Inserting a variable in a raw sql query Laravel

后端 未结 3 485
既然无缘
既然无缘 2021-01-05 01:33

I am inside a function in a controller.

So from the Form, I get a value for a variable, say:

$x = \"whatever\";

Then I need to embe

3条回答
  •  生来不讨喜
    2021-01-05 02:14

    This is one example for you to insert variable in a raw sql laravel

            $query_result = Event::select(
                DB::raw('(CASE WHEN status = "draft" THEN "draft" 
                WHEN events.end_time <= \''.$now.'\' THEN "closed"
                ELSE "available"
                END) AS status'))
                ->orderBy('status')
                ->get();
    

提交回复
热议问题