如何将 sql 命令转换为 laravel eloquent

How to convert sql command to laravel eloquent

这是我使用 mysql 命令的代码

SELECT * FROM `order_list` WHERE currentdate like '%12%' and currentdate like '%2017%'

但我在将其转换为 laravel eloquent.

时遇到问题
$orderlists = Orderlist::where('currentdate', 'like', "%$month%")
                                    ->where('currentdate', 'like', "%$year%")
                                    ->get();

这是正确的吗?谢谢

您还可以使用原始 sql 查询,如下所示

$orderlists = DB::select("SELECT * FROM `order_list` WHERE currentdate like '%12%' and currentdate like '%2017%'");
$orderlists = Orderlist::whereMonth('currentdate', 'LIKE','%'.$month.'%')
                                ->whereYear('currentdate', 'LIKE', '%'.$year.'%')
                                ->get();