vendredi 13 novembre 2020

How to use eloquent ->with method on collection

You may find the question stupid. I may not be doing the research well so I thought to ask it here. I would like to know how to use ->with on collection or what is its equivalent. Here is the code:

$theLastCommentOfThisPost = $post->comments->with('user')->sortByDesc('id')->first();

I would like to get something like this:

Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [id] => 19
            [commentable_type] => App\Post
            [commentable_id] => 123
            [comment] => totoototo
            [is_approved] => 1
            [user_id] => 1
            [created_at] => 2019-04-01
            [updated_at] => 2020-02-04
            [user] => App\User Object
                    (
                        [id] => 1
                        [name] => App\Post
                        [email] => totos@toto.fr
                    )
        )

)

thanks



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

Aucun commentaire:

Enregistrer un commentaire