N
N
NubasLol2019-02-04 18:42:17
Laravel
NubasLol, 2019-02-04 18:42:17

Laravel 'take' how to use in with?

$post = $user->posts()
    ->with(['messages' => function($query){
        return $query->latest()->latest('id')->take(1);
    }])

This code works if you remove take(1) . If you leave it, it works only for the first post
What can be the solution? I tried to create a separate link in the model and include take there, but it didn’t work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2019-02-05
@NubasLol

https://laravel.com/docs/5.7/eloquent-relationship...
Red paragraph

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question