Support the ongoing development of →
Requests Eloquent Forms
Last updated 1 year ago.

It would work that.

Possible way to solve this:

  1. You need to specify the route for this action: Route::post('/comments/store/{article}', [ 'uses' => 'CommentController@store' ]);

  2. You need to register model for a router (in RouteServiceProvider, boot method): $router->model('article', 'App\Article'); // or whenever it is defined.

  3. In store() method will you receive instance of the article, nor ID of it but whole object.

Hope this will help.


Hi androschukandriy!

Well, actually I've registered the route Model Binding with the "Article" Model.

I finally could solve the problem but I'm not sure if It's the best/safest way... I passed the variable through the Form with a "hidden" input.

This is the code if sometime can help:

The Form code: (It's from the show article view and it has the "$article" variable)

<h5><strong>Add a comment:</strong></h5>

    {!! Form::open(['url' => 'comments' ]) !!}
    {!! Form::hidden('article_id', $article->id) !!}
    {!! Form::close() !!}

This is the controller's code:

public function store(CommentRequest $request)

       flash()->success('Comment Added!');

       return redirect()->back();

And finally the route:

Route::resource('comments', 'CommentController');
Last updated 8 years ago.

You didn't specify that the URL has to accept article_id. Please see the route I've meant.


Sign in to participate in this thread!


Your banner here too?

Polinicles polinicles Joined 26 Nov 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.