Replace Dot Notation Laravel Relationship with Nasted Array
hardyweb

hardyweb @hardyweb

About: Highly motivated and self-directed IT professional with a strong foundation in web development (particularly Laravel) and a passion for continuous learning.

Location:
Terengganu, Malaysia
Joined:
Jun 20, 2022

Replace Dot Notation Laravel Relationship with Nasted Array

Publish Date: Sep 26 '24
1 1
https://github.com/laravel/framework/pull/42690
Enter fullscreen mode Exit fullscreen mode
// before...

User::with([
    'avatar',
    'posts.tags',
    'posts.author',
    'posts.featureImage',
    'posts.comments.tags' => fn ($q) => $q->latest(),
])->get();

// after...

User::with([
    'avatar',
    'posts' => [
        'tags',
        'author',
        'featureImage',
        'comments' => [
            'tags' => fn ($q) => $q->latest(),
        ],
    ],
])->get();
Enter fullscreen mode Exit fullscreen mode

Comments 1 total

Add comment