O
O
ortsuev332019-11-01 10:06:50
Laravel
ortsuev33, 2019-11-01 10:06:50

What is the easiest way to get related data?

What is the easiest way to get related data?

$result=$article->comments()->OrderBy('id','desc')->skip($skip)->take($limit)->get();

I have such a pagination, how to get from the user table and so on?
$res=$article->comments()->OrderBy('id','desc')->skip($skip)->take($limit)->User->get()

this doesn't work.
It is possible to sort through in foreach and to address so $res->user->name
and td.
May I say? without overkill?
$res=$article->comments()->OrderBy('id','desc')->skip($skip)->take($limit)->User->get()
like this. there will be two queries
$result=$article->comments()->OrderBy('id','desc')->skip($skip)->take($limit)->get();
and what if there is such ($article->comments()->OrderBy('id','desc')->skip($skip)->take($limit)->User->get() )
I hope idea explained

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ramm, 2019-11-01
@ortsuev33

As far as I understood you need to use with
https://laravel.com/docs/6.x/eloquent-relationship...
You will have something like
For pagination use paginate() method
https://laravel.com/ docs/5.8/pagination#paginating...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question