Laravel 4 where in condition with DB::select query

后端 未结 3 1624
感动是毒
感动是毒 2021-01-21 06:34

I have next SQL query:

SELECT summary_table.device_id, WEEKDAY(summary_table.day) as day, AVG(summary_table.shows) as avg_shows
    FROM (
         SELECT device         


        
相关标签:
3条回答
  • 2021-01-21 07:09

    Take a look at the docs here, scroll down to "Using Where In With An Array":

    http://four.laravel.com/docs/queries

    The whereIn method takes an array, so pass in $var directly, no need to implode.

    ->whereIn('device_id', $var)
    
    0 讨论(0)
  • 2021-01-21 07:18

    Laravel is using PDO library. Sadly, binding with PDO doesn't work with WHERE IN. You can read about it here.

    So what you have to do is to put prepared string in your query like this:

    "(...)
        WHERE device_id IN (".array(implode(',', $var)).")
        (...)"
    
    0 讨论(0)
  • 2021-01-21 07:29
    "(...)
        WHERE device_id IN (".implode(',', $var).")
        (...)"
    
    0 讨论(0)
提交回复
热议问题