在我的Laravel项目中,我的路线可能存在问题



我的页面上有一个未定义的变量错误。 我正在使用一个包聊天器,我正在添加一个字段来向帖子添加评论,例如 StackOverflow。 但是当我路由ChatterReplyController@show并传递变量$chatterreplies视图页面显示未定义的变量时。

这是控制器的代码

public function show($id)
{
$chatterreplies = Chatterreply::where('chatter_post_id',$id)->get();
echo "<pre>"; print_r('$chatterreplies'); die();
// or use the laravel helper 
dd($chatterreplies);
return view('chatter::discussion', compact('chatterreplies'));
}

路由文件代码发布组

Route::group([
'as'     => 'posts.',
'prefix' => $route('post', 'posts'),
], function () use ($middleware, $authMiddleware) {
// All posts view.
Route::get('/', [
'as'         => 'index',
'uses'       => 'ChatterPostController@index',
'middleware' => $middleware('post.index'),
]);
// Create post view.
Route::get('create', [
'as'         => 'create',
'uses'       => 'ChatterPostController@create',
'middleware' => $authMiddleware('post.create'),
]);
// Store post action.
Route::post('/', [
'as'         => 'store',
'uses'       => 'ChatterPostController@store',
'middleware' => $authMiddleware('post.store'),
]);
//Adding Comments
Route::post('/reply/{id}', [
'as'         => 'store',
'uses'       => 'ChatterReplyController@store',
'middleware' => $authMiddleware('post.reply.store'),
]);
//showing Comment
Route::get('/reply/{id}', [
'as'         => 'show',
'uses'       => 'ChatterReplyController@show',
'middleware' => $authMiddleware('post.reply.show'),
]);

这是我在视图页面上显示我的内容的方式

@foreach($chatterreplies as $chatterreply)
{{$chatterreply->reply}}
@endforeach

试试这个

public function show($id)
{
$chatterreplies = Chatterreply::where('chatter_post_id',$id)->get();
echo "<pre>"; print_r('$chatterreplies'); die();
return view('chatter::discussion', compact('chatterreplies'));
}

在你的route你通过一个parameter

相关内容

  • 没有找到相关文章

最新更新