问题
I have following code. the result i get is a single array. is there any way i can make it a nested array?
$contents = RecentView::where('recent_views.user_id', $loggedUser)
->leftJoin('feed_posts','recent_views.post_id','=','feed_posts.id')
->leftJoin('users','feed_posts.user_id','=','users.id')
->paginate(12)->toArray();
and the result is:
[id] => 71
[user_id] => 71
[post_id] => 529
[site_id] => 103
[date_time] => 2020-11-05 00:00:00
[title] => Lorem Ipsum
[description] => Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem
Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum
[image] => PiZ0OCrH.jpg
[hit] => 609
[website_id] => 103
[created_at] => 2012-05-02T00:00:00.000000Z
[name] => Franko
[username] => franko
[email] => test@test.com
But the Result i need is like:
[recent_views]=>
[id] => 71
[user_id] => 71
[post_id] => 529
[site_id] => 103
[date_time] => 2020-11-05 00:00:00
[post]=>
[title] => Lorem Ipsum
[description] => Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem
Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum
[image] => PiZ0OCrH.jpg
[hit] => 609
[website_id] => 103
[created_at] => 2012-05-02T00:00:00.000000Z
[user]=>
[name] => Franko
[username] => franko
[email] => test@test.com
is there any way to do this in laravel query builder?
来源:https://stackoverflow.com/questions/64880729/laravel-query-builder-with-join-table-as-nested-array