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] => 2022-04-01
[updated_at] => 2022-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

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time