0

Share

WEB DEVELOPMENT

How To Integrate Eager Lazy Collections To Laravel

  • Home
  • Blogs
  • How To Integrate Eager Lazy Collections To Laravel

Eager loading gets all data records in a single query and Lazy loading requires N+1 queries. Laravel's LazyCollection class is a powerful tool with brief memory.

Vimal Tarsariya

July 14, 2022

The Laravel team announced the immediate availability of Laravel version 6.1.0 with a new Eager method added to Lazy Collections along with the latest updates to Laravel. A Lazy Collection is a new feature added to Laravel 6, which has an Eager method that enumerates all of the lazy collection’s values and constructs a new Lazy Collection instance, which will be backed by an array.

In this step-by-step guide, you will learn about the integration of Eager Lazy Collections into Laravel.

Step - 1:

Without Eager() The below mentioned Would Fetch Results Twice

An example illustrates its use:

Step - 2:

The Purge() And GetChannels() Methods Were Added

Next, the purge() and getChannels() methods were added to the LogManager class in order to purge resolved log driver/channel. The test in illustrates its use:

Step - 3:

A New AssertNoContent() Method Was Added To The TestResponse Class

// Before

// After

Step - 4:

A New WithCookies Method Was Added To TestResponse, Making It Easier To Send Cookies In HTTP Tests

// Before

// After

You can see the full list of new features and updates below, and the difference between6.0.4 and 6.1.0 on GitHub. The full release notes for Laravel 6.0 are available in the GitHubv6 changelog

New Features And Updates V6.1.0

Added

Added Illuminate\Support\LazyCollection::eager() method.

Added purge() and getChannels() methods to Illuminate\Log\LogManager.

Added Illuminate\Foundation\Testing\TestResponse::assertNoContent() method.

Added InteractsWithQueue to SendQueueNotifications.

Added SendQueueNotifications::retryUntil() method.

Added methods for sending cookies with test requests.

Added support of job middleware for queued notifications.

Fixed

Fixed migration class duplicate check in make: migration command.

Fixed monolog v2 handler preparation.

Fixed return of callback value for DurationLimiter.

Changed

Added runtime information output for seeders.

Added strict parameter to Illuminate\Foundation\Testing\TestResponse::assertJsonPath().

Added deletedAtColumn optional parameter to Foundation\Testing\Concerns\InteractsWithDatabase::assertSoftDeleted().

Improved

Improved AuthServiceProvider::registerEventRebindHandler() in case if guard is not initialized.

Conclusion:

Laravel's Eager Lazy Collection is a powerful tool that allows you to process all data with very little memory. Hence, try to learn the process of integration and start using it for your client's project.

img

Vimal Tarsariya

Project Manager at Vasundhara Infotech, a leading software development company. His great planning and execution qualities led to several successful projects.

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Latest 13 Web Development Trends To Expect In 2022
April 11, 2022 Category : company news

Revealing Vasundhara’s New Identity

Read More
Leave a Comment