samedi 30 mars 2019

How can I loop in polymorphic relation by passing query reference?

I dont know if its called query reference. Feel free to make edits.

I have a polymorphic relation on my Article Model:

public function comments(){

        return $this->morphMany(Comment::class, 'commentable');

    }

Now I have to send a polymorphic relation data to my view.

public function show(Article $article)
    {

        return view('article.show',[
            'article' => $article,
            'comments' => $article->comments()
        ]);
    }

I'm sending it by $article->comments() because I want to use each comments eloquent relations.

On my blade:

@foreach($comments as $comment)
                 //This won't execute. What is wrong?
@endforeach

if I dd(comments) before foreach I've this: enter image description here



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

Aucun commentaire:

Enregistrer un commentaire