Laravel 5.4 - 错误调用未定义的方法 Illuminate\Http\JsonResponse::count()

Laravel 5.4 - Error Call to undefined method Illuminate\Http\JsonResponse::count()

当我将集合从 composer 传递到我的视图时,有时会出现此错误。

我在这一行有这个错误:

@if(!empty($running_out_offers->count()))
  .....
@endif

我不知道这有什么问题,也无法调试它,因为它有时会发生,即使我没有操作数据等。

这是我的控制器:

namespace App\Http\Controllers;

use App\Enums\PostType;
use App\Models\Blog\BlogPost;
use App\Models\Campaign;

class WebsiteController extends Controller
{
    function homepage(){

      return view('website.homepage');
    }
}

这是我的作曲家 :

function compose(View $view)
{

    if ($view->getName() == 'website.homepage') {
        $view->with([
            'running_out_offers'   => $this->runningOutOffers(4),
         ]);
     }
} 

private function runningOutOffers($limit = null,$fields = '')
{
    return $this->remember('runningOutOffers', 1, function () use ($limit,$fields) {
        return offerAndEntity($limit, function ($query) {
            $query->main()->runningOut();
        },null,$fields);
    });
}


   function remember($key, $time, $callback)
{
    return cache()->store('file')->remember('prefix_'.$key, $time, $callback);
}

这个returns一个合集。

谁能告诉我这是怎么回事? :(

是否可能因为缓存?!

已编辑:

{{ dd($running_out_offers) }} 显示:

 Collection {#1038 ▼
  #items: array:1 [▼
  0 => Entity {#980 ▼
  #fillable: array:20 [▶]
  #attach: array:1 [▶]
  #presenter: "App\Presenters\EntityPresenter"
  #casts: array:1 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:9 [▼
    "id" => 42807
    "title" => "Offer Title"
    "type" => "SERVICE"
    "is_parent" => 1
    "parent_id" => null
    "attachments" => "{"icon":"fdc839958987caad5ba67016fcd77eaf.jpg"}"
    "available_children" => 2
    "sold" => 21
    "is_available" => 1
  ]
  #original: []
  #dates: []
  #dateFormat: null
  #appends: []
  #events: []
  #observables: []
  #relations: array:1 [▶]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]
  #forceDeleting: false
  #public_path: "/home/shikoff/public_html"
  #upload_path: "/home/shikoff/public_html/upload/entity"
  #upload_relative_path: "upload/entity"
  #presenterInstance: null
}

] }

尝试-

@if(count($running_out_offers)>0)
  .....
@endif

您必须 return 查询构建器才能使用计数函数,而不是 return 集合