我的控制器中有以下操作:
public function viewPost($id)
{
$current_post = forum_post::with('replies')->where('id', $id)->get();
return view('forumViewPost',['currentPost', $current_post]);
}
然后我有以下观点:
@extends('layout.app')
@section('content')
<div class="container">
<div class="nk-gap-2"></div>
<ul class="nk-forum nk-forum-topic">
<li>
<div class="nk-forum-topic-author">
<img src="assets/images/avatar-2-sm.jpg" alt="Kurt Tucker">
<div class="nk-forum-topic-author-name" title="Kurt Tucker">
<a href="#">{{$currentPost->nickname}}</a>
</div>
<div class="nk-forum-topic-author-role">
Member
</div>
</div>
<div class="nk-forum-topic-content">
{{$currentPost->content}}
</div>
<div class="nk-forum-topic-footer">
<span class="nk-forum-topic-date">June 19,
2017</span> <span class="nk-forum-action-btn"><a href="#forum-reply" class="nk-anchor"> Reply</a></span>
<span class="nk-forum-action-btn"><a href="#"> Spam</a></span>
<span class="nk-forum-action-btn"><span class="nk-action-heart liked"><span class="num">1</span>
Like</span></span>
</div>
</li>
@foreach($currentPost->replies as $replies)
@endforeach
</ul>
</div>
@endsection
现在当我跑这个.我收到以下错误:
Undefined variable: currentPost
谁能告诉我我做错了什么?
解决方法:
如果您使用[],您可以写这个[‘currentPost’=> $current_post]
所有
public function viewPost($id)
{
$current_post = forum_post::with('replies')->where('id', $id)->get();
return view('forumViewPost',['currentPost' => $current_post]);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。