我想在查询构建器中使用这样的数据库查询:
$now = new Carbon;
$feed = Post::where([
['active' => 1],
['published' => $now]
])
-> take(5)
-> get()
-> toArray();
我做了什么:
SELECT * FROM posts WHERE active = 1 AND published = '{$now}' LIMIT 5
但它就像:
<
如何使用<=
方法制作>
,>=
,<>
,LIKE
,::where
和UPDATE your_table
SET displayorder = displayorder + X * C;
语句?
答案 0 :(得分:3)
像这样使用['published','>=',$now]
$now = new Carbon;
$feed = Post::where([
['active', '=', '1'],
['published','>=',$now]
])
->take(5)
->get()
->toArray();
或使用单独的函数
$now = new Carbon;
$feed = Post::where('active', 1)->where('published','>=', $now)
->take(5)
->get()
->toArray();
答案 1 :(得分:1)
锋
$feed = Post::where('active','=',1)->where('published','<=',$now)->get();
答案 2 :(得分:1)
使用此
$feed = Post::where('active',1) ->where('published','<=',$now) ->take(5) ->get() ->toArray();
请参阅手册:https://laravel.com/docs/master/queries#raw-expressions