get
在cursor
返回空白
$excep[] = DB::table('table')->where('user_id', $user)->select('data')->get();
return $excep; // returns some sql data
但是cursor
:
$excep[] = DB::table('table')->where('user_id', $user)->select('data')->cursor();
return $excep; // returns [{}]
信息不足以理解:https://laravel.com/docs/5.5/eloquent#chunking-results
答案 0 :(得分:0)
cursor
仅可用于迭代,如果您一次需要所有数据,则必须使用get
。
// All users will be loaded on memory first on collection and then, iterate.
// You can return all users as return UserModel::get();
foreach (UserModel::get() as $user) {
$this->sendWellcomeMail($user);
}
// Only one user on memory on each iteration.
// You can NOT return all users with return UserModel::cursor();
foreach (UserModel::cursor() as $user) {
$this->sendWellcomeMail($user);
}