vendredi 9 mars 2018

Pass an object to a route parameter without model binding

I have a route like this:

Route::post('{object}', 'CommentController@store')->name('store');

And I want to pass an object as argument to my form action like this:

<form action="" method="post" id="comment--form"></form>

Here is the problem

if I pass my query object as you know I will get the id of query object
if I pass something like this: I will get exception and for some polymorphism reason I can't use model binding because the object could be any object so I'm wondering if there is any solution for my question

PS
I have a polymorphic comment system and I dont know if it's decoration design pattern or not but I want to save comments dynamically via my interface so I want to save comments dynamically like this:

   public function store(Request $request, $object)
    {
        // comments() is an implementation of an interface
        $object->comments()->create([
            'name' => auth()->check() ? $request->user()->fullName() : $request->name,
            'email' => $request->user()->email ?? $request->email,
            'comment' => $request->content,
        ]);
    }

But I can't pass an object as argument is there anyway to pass it through route or any other idea or solution?
Thanks.



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

Aucun commentaire:

Enregistrer un commentaire