从 Laravel 5.2 更新到 5.3 后,调用数组上的成员函数 all()

Posted

技术标签:

【中文标题】从 Laravel 5.2 更新到 5.3 后,调用数组上的成员函数 all()【英文标题】:Call to a member function all() on array After update from Laravel 5.2 to 5.3 【发布时间】:2017-10-03 14:47:57 【问题描述】:

从 5.2 更新 Laravel 5.3 之后出现错误

Builder.php 第 638 行中的 FatalErrorException: 调用数组上的成员函数 all()

我使用 Laravel shift 工具升级框架,成功更新作曲家后,我遇到了这个问题。

代码

public function index()

    $static_block_array = [];
    $static_block       = StaticBlock::whereIn('identifier', [
        'DESKTOP_STORE_FRONT_ROW_1_BLOCK',
        'DESKTOP_STORE_FRONT_ROW_2_BLOCK',
        'DESKTOP_BOTTOM_BLOCK','SOCIAL_MEDIA_ICON_BLOCK','TOP_ROW_HOMEPAGE_BLOCK'])
        ->remember(cacheTimeOut(CATALOG_CACHE_TIMEOUT))
        ->with("staticBlockContent")
        ->cacheTags(TAG_CATALOG)
        ->whereStatus(1)
        ->get();

    foreach ($static_block as $value) 
        $static_block_array[$value->identifier] = isset($value->staticBlockContent[0]) ? $value->staticBlockContent[0]->content : "";
    

    return View::make('home/index')
            ->with('desktop_store_front_first_row', array_get($static_block_array, 'DESKTOP_STORE_FRONT_ROW_1_BLOCK', ''))
            ->with('desktop_store_front_second_row', array_get($static_block_array, 'DESKTOP_STORE_FRONT_ROW_2_BLOCK', ''))
            ->with('desktop_top_row_content', array_get($static_block_array, 'TOP_ROW_HOMEPAGE_BLOCK', ''))
            ->with('desktop_bottom_block', array_get($static_block_array, 'DESKTOP_BOTTOM_BLOCK', ''));

【问题讨论】:

你能发布有问题的sn-ps吗? @BagusTesa 已添加,请立即查看 @BagusTesa 我得到的错误在供应商目录上显示错误,供应商/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php 第 638 行: 调用->all()的那个,它在哪里调用?在您的代码中,或者更确切地说,在该有问题页面的控制器中。 @BagusTesa 它位于供应商目录中的框架函数上,由 laravel 框架创建 【参考方案1】:

问题现已解决。 我们创建了一个自定义逻辑来缓存查询中的记忆方法我们返回一个普通数组,但在转换为集合对象后问题就解决了。

 return collect($cache->remember($key, $minutes, $callback));

【讨论】:

以上是关于从 Laravel 5.2 更新到 5.3 后,调用数组上的成员函数 all()的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5.3 用户验证源码探究 路由与注册

在升级laravel 5.2到5.3之后,无法在Route :: model中绑定模型

更新到 Laravel 5.3 后播种时调用未定义的方法 Illuminate\Database\Query\Builder::lists()

Laravel 5.2 或 5.3:如何正确实施检查会话是不是已登录

在更新到Laravel 5.3后播种时调用未定义的方法Illuminate Database Query Builder :: lists()

将 Laravel 从 5.3 升级到 5.4