调用非对象上的成员函数count()(Laravel 5) [英] Call to a member function count() on a non-object (Laravel 5)
本文介绍了调用非对象上的成员函数count()(Laravel 5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目列表,可以单击并在其中(需要)显示项目名称,以及项目任务列表(ToDo应用程序)
I have a list of projects, where I can click on and it (needs to) show the project name, and the list of the projects' tasks (ToDo application)
但是当我单击某个项目时,会出现此错误.
But when I click on a certain project I get this error.
(将显示"H2"项目名称)
(The "H2" project name will show up)
h2>{{{ $project->name }}}</h2>
@if ( !$project->tasks->count())
There are no tasks for this project.
@else
<ul>
@foreach( $project->tasks as $task)
<li><a href="{{ route('projects.tasks.show', [$project->slug, $task->slug]) }}">{{ $task->name }}</a></li>
@endforeach
</ul>
@endif
推荐答案
$project->tasks
是一个数组,您不能在该数组上调用count()
.因此,请尝试-
$project->tasks
is an array and you cant call count()
on the array. So try with -
count($project->tasks)
这篇关于调用非对象上的成员函数count()(Laravel 5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文