尽管已定义“未定义的变量”

时间:2019-07-02 17:00:58

标签: php laravel

此视图应显示帖子的评论。尽管我已定义comments,但仍然收到以下错误:

  

未定义变量:注释(查看:C:\ xampp \ htdocs \ StuffSpot \ resources \ views \ dashboard.blade.php)

步骤如下:

  1. 这是发生错误的行:
@foreach ($comments as $comment)
  1. 以下是表单的路由:
<form action="{{route('comment.create')}}" method="post">
  1. comment.create路线:
    Route::post('/createcomment', [
        'uses' => 'PostController@postCreateComment',
        'as' => 'comment.create',
        'middleware' => 'auth'
    ]);
  1. PostCreateComment具有一些插入代码和以下内容:
return redirect()->route('dashcomment')->with(['message' => $message]);
  1. dashcomment路线:
    Route::get('/dashcomment', [
        'uses' => 'PostController@getDashComment',
        'as' => 'dashcomment',
        'middleware' => 'auth'
    ]);
  1. getDashComment函数:
    public function getDashComment()
    {
        $comments = Comment::orderBy('created_at', 'desc')->get();
        return view('dashboard', ['comments' => $comments]);
    }

0 个答案:

没有答案
相关问题