【发布时间】:2014-02-01 23:18:30
【问题描述】:
我正在将 Laravel 4 用于我正在进行的项目。我需要从帖子中检索第一条评论。我使用以下代码来执行此操作。
$comments = Comment::where('post_id', $post->id)->first();
这成功检索了第一条评论(我知道这是因为我print_r-ed $comments 并且它返回了所有正确的信息)。
但是,下面这行代码触发了错误__toString() must not throw an exception
<td>{{$comments->content}}</td>
当我print_r-ed 它返回类型字符串时,也返回了正确的字符串。那它为什么还要在$comments->content 已经是字符串的情况下尝试将其转换为类型字符串?
【问题讨论】:
-
它表示
View类的__toString()方法不能抛出异常。可能,您的视图中有一些错误 -
Symfony \ Component \ Debug \ Exception \ FatalErrorException Method Illuminate\View\View::__toString() must not throw an exception是完整的错误@neoascetic。另外,那会是什么错误? -
@735Tesla 没有告诉我我做错了什么
-
@InsertNameHere 未定义变量。未闭合的花括号。事实上,任何类型的错误