samedi 9 septembre 2017

Laravel - Using trait in resource controller

I am trying to use trait as a typehint for my resource controllers.

My Controller

public function store(CreateCommentRequest $request, Commentable $commentable)

Here, commentable is a typehint, which my Eloquent models use. Commentable contains the method for retrying comments using MorphMany.

In my routing, I have:

Route::resource('order.comment', 'CommentController')
Route::resource('fulfillments.comment', 'CommentController')

Both orders and fulfillments can have comments, and use the same controller, because the code would be the same.

However, when i post to order/{order}/comment i get the following error:

Illuminate\Contracts\Container\BindingResolutionException
Target [App\Models\Morphs\Commentable] is not instantiable.

Is it possible to make this approach possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire