Laravel-5 'LIKE' 等价物 (Eloquent) [英] Laravel-5 'LIKE' equivalent (Eloquent)
本文介绍了Laravel-5 'LIKE' 等价物 (Eloquent)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码从 Laravel 5 的数据库中提取一些结果.
I'm using the below code to pull some results from the database with Laravel 5.
BookingDates::where('email', Input::get('email'))->orWhere('name', 'like', Input::get('name'))->get()
然而, orWhereLike 似乎没有匹配任何结果.该代码在 MySQL 语句方面产生什么?
However, the orWhereLike doesn't seem to be matching any results. What does that code produce in terms of MySQL statements?
我正在尝试实现以下目标:
I'm trying to achieve something like the following:
select * from booking_dates where email='my@email.com' or name like '%John%'
推荐答案
如果您想查看数据库中运行的内容,请使用 dd(DB::getQueryLog())
来查看哪些查询运行.
If you want to see what is run in the database use dd(DB::getQueryLog())
to see what queries were run.
试试这个
BookingDates::where('email', Input::get('email'))
->orWhere('name', 'like', '%' . Input::get('name') . '%')->get();
这篇关于Laravel-5 'LIKE' 等价物 (Eloquent)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文