Php 查看can';t查找变量(laravel)

Php 查看can';t查找变量(laravel),php,laravel,Php,Laravel,我的控制器中有以下操作: 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')

我的控制器中有以下操作:

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

谁能告诉我我做错了什么吗?

如果你使用
[]
你可以写这个
['currentPost'=>$current\u post]

全部


您还可以使用
compact(“”)和如我们所述,将
$current\u post
更改为
$currenctpost

public function viewPost($id)
{
  $currentPost = forum_post::with('replies')->where('id', $id)->get();
  return view('forumViewPost', compact('currentPost'));
}

你来了!如果发生这种情况,请将
$current\u post
更改为
$currentPost
:)是的,我注意到了,因为我要写同样的答案,一个提示,坚持一个变量的命名风格。如果你想使用camelCase,就坚持使用它。这是避免此类问题的一种方法:)(通过这样做,您可以使用
compact
方法轻松地将变量传递给视图)
public function viewPost($id)
{
    $current_post = forum_post::with('replies')->where('id', $id)->get();
    return view('forumViewPost',['currentPost' => $current_post]);
}
public function viewPost($id)
{
  $currentPost = forum_post::with('replies')->where('id', $id)->get();
  return view('forumViewPost', compact('currentPost'));
}