find in set in laravel ? example

前端 未结 2 740
旧巷少年郎
旧巷少年郎 2020-12-16 15:30

I am new in laravel. My query is i need to find out value from comma separated field.

Here is my table:

tags_value

╔════╦══         


        
相关标签:
2条回答
  • 2020-12-16 16:09

    You need to escape the call to FIND_IN_SET() using quotes:

    $query = DB::table('tags_value')
             ->whereRaw('FIND_IN_SET(css,Tags)')
             ->get();
    

    If you want to parameterize the column for which you search in FIND_IN_SET, then you can try something like this:

    $colname = 'css'
    $query = DB::table('tags_value')
             ->whereRaw('FIND_IN_SET(?,Tags)', [$colname])
             ->get();
    
    0 讨论(0)
  • 2020-12-16 16:12

    Try this :

    ->whereRaw("FIND_IN_SET('css',tags)")
    
    0 讨论(0)
提交回复
热议问题