首页 > 解决方案 > Laravel 在使用 get() 或 all() 雄辩方法时抛出“Memory Size Exhausted”错误

问题描述

无论数据库中是否存在值,请 Laravel 在使用 get() 或 all() 雄辩方法时抛出“内存大小耗尽”错误。但是当我使用 first() 方法时,它给出了预期的结果。这是不寻常的。谁能帮忙?

例如这个

$transaction_history = Form::all(); // Produces the error
dd($transaction_history);

或这个

$transaction_history = Form::get(); // Produces the error
dd($transaction_history);

预期会产生 null 以表示没有结果或对象集合!

但是这个

   $transaction_history = Form::first(); // Works fine

标签: phplaravel

解决方案


如何接收前 100 行并且不破坏你的记忆?

$transaction_history = Form::first(function ($value, $key) {
    return $key < 99;
});

推荐阅读