Get the first element of a relationship with Eloquent

I would know if it is possible to get the first element of communication with Eloquent.

This does not work:

$posts = Post::with(['medias' => function($q) { $q->where('type', 'landscape') // not working ->limit(1); // not working ->take(1); // not working ->first(); }])->get(); 

This is a one-to-many relationship.

Thank you in advance!

+5
source share

Source: https://habr.com/ru/post/1209369/


All Articles