laravel 允许的内存大小为 134217728 字节耗尽(尝试分配 74735240 字节)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43878422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:56:16  来源:igfitidea点击:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 74735240 bytes)

laravel

提问by Dmitry Malys

i try to create a search form in my laravel project.

我尝试在我的 Laravel 项目中创建一个搜索表单。

So i want to pass all the almost all table columns to the view so i can so i can use them to create dropboxes, checkboxes and etc.

所以我想将所有几乎所有的表列传递给视图,这样我就可以使用它们来创建保管箱、复选框等。

But when i use $var = Model::all();it return this error:

但是当我使用$var = Model::all();它时会返回此错误:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 74735240 bytes)

允许的内存大小为 134217728 字节耗尽(尝试分配 74735240 字节)

Can you advise me another solution?

你能告诉我另一种解决方案吗?

This is my controller:

这是我的控制器:

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use App\Lot;

class SearchController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $lots = Lot::all();
        return view('lots.search')->withLot($lots);
    }
}

Thank you!

谢谢!

采纳答案by donquixote

There is too much data to fit in memory. You should probably paginate your result set.

有太多数据无法放入内存。您可能应该对结果集进行分页。

https://laravel.com/docs/5.4/pagination#basic-usage

https://laravel.com/docs/5.4/pagination#basic-usage

public function index()
{
    $lots = DB::table('lots')->paginate(15);

    return view('lots.search', ['lots' => $lots]);
}

Or you can increase the memory limit, but that's not the best solution.

或者您可以增加内存限制,但这不是最佳解决方案。

ini_set('memory_limit','160M');