如何在 Laravel 5 和查询生成器中编写“OR WHERE YEAR(...) 子句?
How to write a "OR WHERE YEAR(...) clause in Laravel 5 and Query Builder?
重现 WHERE YEAR(...)
的 wereYear() 函数存在,但是 OR WHERE YEAR(...)
呢?
例如,这个怎么写?
WHERE YEAR('date_start') = 2015 OR WHERE YEAR('date_start') = 2016
$query->whereYear('date_start', '=', 2015)->????
我已经知道怎么做了,这里是解决方案。
->orWhere(function($nest) use($year) {
$nest->whereYear('date_start', '=', $year);
});
这应该适合你:
$years = ['2015', '2016'];
$table_records = TableName::whereIn(DB::raw("year(date_start)"), $years)->get();
重现 WHERE YEAR(...)
的 wereYear() 函数存在,但是 OR WHERE YEAR(...)
呢?
例如,这个怎么写?
WHERE YEAR('date_start') = 2015 OR WHERE YEAR('date_start') = 2016
$query->whereYear('date_start', '=', 2015)->????
我已经知道怎么做了,这里是解决方案。
->orWhere(function($nest) use($year) {
$nest->whereYear('date_start', '=', $year);
});
这应该适合你:
$years = ['2015', '2016'];
$table_records = TableName::whereIn(DB::raw("year(date_start)"), $years)->get();