vendredi 7 septembre 2018

There May Be Problem In My Route In my Laravel Project

There is an undefined variable error on my page. I am working with a package chatter and I am adding a field to add comments to the post like StackOverflow. But when I am routing the ChatterReplyController@show and passing $chatterreplies variable the view page is showing undefined variable.

This is the code of controller

    public function show(Chatterreply $chatterreply ,$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 File Code Post Group

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'),
    ]);

And Here is how I am showing my content on the view page

@foreach($chatterreplies as $chatterreply)
                        
@endforeach



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2wUrvlb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire