DEV Community

hardyweb
hardyweb

Posted on

1

Replace Dot Notation Laravel Relationship with Nasted Array

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

Top comments (1)

Collapse
 
mitch1009 profile image
Mitch Chimwemwe Chanza

What on earth is Nasted array

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay