Php Laravel 5.4-对未定义的方法Illumb\Http\JsonResponse::count()的错误调用
当我从composer将集合传递到视图时,有时会出现此错误 我在这行上有一个错误:Php Laravel 5.4-对未定义的方法Illumb\Http\JsonResponse::count()的错误调用,php,json,laravel,collections,httpresponse,Php,Json,Laravel,Collections,Httpresponse,当我从composer将集合传递到视图时,有时会出现此错误 我在这行上有一个错误: @if(!empty($running_out_offers->count())) ..... @endif 我不知道这有什么问题,也不能调试它,因为它有时甚至在我没有操作数据时发生 这是我的控制器: namespace App\Http\Controllers; use App\Enums\PostType; use App\Models\Blog\BlogPost; use App\Models
@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);
}
这将返回一个集合
谁能告诉我有什么问题吗(
这可能是因为缓存吗
编辑:
{{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
您必须返回查询生成器才能使用计数功能,而不返回集合您能否在视图中
{dd($running_out_offers)}
并显示它所显示的内容。我编辑了这篇文章,现在您可以看到了。@WreighI很抱歉,我无法查看图像,因为我的网络代理阻止了它。((我无法控制网络lol)这没问题:)我复制了@Wreighlast的东西,你们能提供一些堆栈跟踪吗?这有点令人难以置信。谢谢@Sohel0415,它可以工作,但我必须等到不再看到那个错误。