我想让所有列的列都是我的字符串的一部分(不是反向的)
我做了这个查询,
SELECT * FROM table WHERE 'string' LIKE CONCAT('%', column, '%')
通过SQL查询工具直接在服务器上运行时,查询可以正常工作。
然而,我正在使用雄辩的ORM,我试图做到以下几点:
$results = MODEL::where('my_string','like',"CONCAT('%',column, '%')")->get();
它抛出了这个错误:
SQLSTATE[42703]: Undefined column: 7 ERROR: column "my_string" does not exist
第1行:
请注意我不是在寻找:
SELECT * FROM table WHERE column LIKE '%string%'
答案 0 :(得分:2)
从上面的评论。如果你已经有一个工作的SQL语句。您可以使用Raw Expressions
MODEL::whereRaw("'string' LIKE CONCAT('%', column, '%')");
有关详情,Raw Expressions
部分中的http://laravel.com/docs/5.0/queries