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

Call to a member function all() on array After update from Laravel 5.2 to 5.3

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

Builder.php 第 638 行中的 FatalErrorException: 调用数组

上的成员函数 all()

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

代码

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', ''));
}

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

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