Select 数据和使用地点和地点 laravel 5.6
Select data and use where and where laravel 5.6
我正在尝试创建 ( (Where and Where) OR (Where and Where) ) 经过大量搜索后我发现了这个
$last_transations = Transcationhistorique::where('sender_id', '=', $user_id)
->where('receiver_id','=', $user_id)
->orderBy('created_at', 'desc')
->skip(3)
->take(3)
->get();
我得到一个空结果
"last 3 transactions": []
如果您正在搜索简单的 where or where
然后使用(使用您的查询):
$last_transations = Transcationhistorique::where('sender_id', $user_id)
->orWhere('receiver_id', $user_id)
->orderBy('created_at', 'desc')->skip(3)->take(3)->get();
如果您正在搜索 where and where
然后使用(使用您的查询):
$last_transations = Transcationhistorique::where(['sender_id' => $user_id, 'receiver_id' => $user_id])
->orderBy('created_at', 'desc')->skip(3)->take(3)->get();
如果您正在搜索 (where and where) OR (where and where)
,那有点复杂,您可以这样查询:
DB::table('users')
->where(['col1' => 'val1', 'col2' => 'val2'])
->orWhere(function ($query) {
$query->where(['col3' => 'val3', 'col4' => 'val4']);
})
->get();
引用here
您可以使用 where 并向其传递函数 例如:
如果我想获取 admin 且 ID 为 4 或 5 的用户
$users->where("type","admin")->where(function($query){
$query->where("id",4)->orWhere("id",5);
})->get();
相当于:
SELECT * FROM users WHERE type = "admin" AND (id = 4 OR id = 5)
我认为您指定的 skip 和取值错误,您可以尝试以下操作吗:
$last_transations = Transcationhistorique::where('sender_id', $user_id)
->orWhere('receiver_id', $user_id)
->orderBy('created_at', 'desc')->skip(0)->take(3)->get();
从文档中说:
skip / take: To limit the number of results returned from the query, or to skip a
given number of results in the query, you may use the skip and take
methods:
您正在做的是跳过 3 并取 3,所以它会像 ->offset(3)->limit(3)
这样 return 为空!
$last_transations = Transcationhistorique::where([['sender_id', '=', $user_id],['receiver_id','=', $user_id]])
->orderBy('created_at', 'desc')
->skip(3)
->take(3)
->get();
给你。
我正在尝试创建 ( (Where and Where) OR (Where and Where) ) 经过大量搜索后我发现了这个
$last_transations = Transcationhistorique::where('sender_id', '=', $user_id)
->where('receiver_id','=', $user_id)
->orderBy('created_at', 'desc')
->skip(3)
->take(3)
->get();
我得到一个空结果
"last 3 transactions": []
如果您正在搜索简单的 where or where
然后使用(使用您的查询):
$last_transations = Transcationhistorique::where('sender_id', $user_id)
->orWhere('receiver_id', $user_id)
->orderBy('created_at', 'desc')->skip(3)->take(3)->get();
如果您正在搜索 where and where
然后使用(使用您的查询):
$last_transations = Transcationhistorique::where(['sender_id' => $user_id, 'receiver_id' => $user_id])
->orderBy('created_at', 'desc')->skip(3)->take(3)->get();
如果您正在搜索 (where and where) OR (where and where)
,那有点复杂,您可以这样查询:
DB::table('users')
->where(['col1' => 'val1', 'col2' => 'val2'])
->orWhere(function ($query) {
$query->where(['col3' => 'val3', 'col4' => 'val4']);
})
->get();
引用here
您可以使用 where 并向其传递函数 例如:
如果我想获取 admin 且 ID 为 4 或 5 的用户
$users->where("type","admin")->where(function($query){
$query->where("id",4)->orWhere("id",5);
})->get();
相当于:
SELECT * FROM users WHERE type = "admin" AND (id = 4 OR id = 5)
我认为您指定的 skip 和取值错误,您可以尝试以下操作吗:
$last_transations = Transcationhistorique::where('sender_id', $user_id)
->orWhere('receiver_id', $user_id)
->orderBy('created_at', 'desc')->skip(0)->take(3)->get();
从文档中说:
skip / take: To limit the number of results returned from the query, or to skip a given number of results in the query, you may use the skip and take methods:
您正在做的是跳过 3 并取 3,所以它会像 ->offset(3)->limit(3)
这样 return 为空!
$last_transations = Transcationhistorique::where([['sender_id', '=', $user_id],['receiver_id','=', $user_id]])
->orderBy('created_at', 'desc')
->skip(3)
->take(3)
->get();
给你。