此视图应显示帖子的评论。尽管我已定义comments
,但仍然收到以下错误:
未定义变量:注释(查看:C:\ xampp \ htdocs \ StuffSpot \ resources \ views \ dashboard.blade.php)
步骤如下:
@foreach ($comments as $comment)
<form action="{{route('comment.create')}}" method="post">
comment.create
路线: Route::post('/createcomment', [
'uses' => 'PostController@postCreateComment',
'as' => 'comment.create',
'middleware' => 'auth'
]);
PostCreateComment
具有一些插入代码和以下内容:return redirect()->route('dashcomment')->with(['message' => $message]);
dashcomment
路线: Route::get('/dashcomment', [
'uses' => 'PostController@getDashComment',
'as' => 'dashcomment',
'middleware' => 'auth'
]);
getDashComment
函数: public function getDashComment()
{
$comments = Comment::orderBy('created_at', 'desc')->get();
return view('dashboard', ['comments' => $comments]);
}