01 logo

The most effective method to Incorporate Eager Lazy Collections to Laravel

The Laravel group declared the prompt accessibility of Laravel form 6.1.0 with another Eager technique added to Apathetic Assortments alongside the furthest down-the-line updates to Laravel.

By Tina ModiPublished 2 years ago 3 min read
1

A Sluggish Assortment is another component added to Laravel 6, which has an Eager strategy that identifies the languid assortment of all values and develops another Lethargic Assortment case, which will be supported by an exhibit.

In this bit-by-bit guide, you will find out about the combination of Eager Lazy Collections in Laravel.

Step - 1:

Without Enthusiastic() The underneath referenced Would Bring Results Two times

A model delineates its utilization:

$users = User::cursor();

$users = $users->eager();

$count = $users->count();

$users->each(function ($user) {

//

});

Step - 2:

The Cleanse() And GetChannels() Strategies Were Added

Then, the cleanse() and get channels() strategies were added to the LogManager class to cleanse the settled log driver/channel. The test delineates its utilization:

public function testLogMnagerPurgeResolvedChannels()

{

$manager = new LogManager($this->app);

$this->assertEmpty($manager->getChannels());

$manager->channel('single')->getLogger();

$this->assertCount(1, $manager->getChannels());

$manager->purge('single');

$this->assertEmpty($manager->getChannels());

}

Step - 3:

Another AssertNoContent() Strategy Was Added To The TestResponse Class

// Previously

$response = $this->get('api/endpoint');

$response->assertStatus(409);

$this->assertEmpty($response->content());

// Later

$response = $this->get('api/endpoint');

$response->assertNoContent(409);

Step - 4:

Another WithCookies Technique Was Added To TestResponse, Making It More straightforward To Send Treats In HTTP Tests

// Previously

$cookies = [

'name1' => encrypt('value1'),

'name2' => encrypt('value2')

];

$response = $this->call('get', 'test', [], $cookies);

// Later

$response = $this->withCookies([

'name1' => 'value1',

'name2' => 'value2'

])->get('test');

You can see the full rundown of new elements and updates beneath, and the distinction between6.0.4 and 6.1.0 on GitHub. The full delivery notes for Laravel 6.0 are accessible in the GitHubv6 changelog

Get a Customized Roadmap to Success with our Laravel Web Development Service

Leverage the expertise of our Microservice architecture experts to develop low-latency apps for mission-critical business solutions. Partner with the top Laravel Development Company and relish your success.

New Elements And Updates V6.1.0

Added

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

Added cleanse() and getChannels() strategies to Illuminate\Log\LogManager.

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

Added InteractsWithQueue to SendQueueNotifications.

Added SendQueueNotifications::retryUntil() strategy.

Added strategies for sending treats with test demands.

Added help of occupation middleware for lined warnings.

Fixed

Fixed movement class copy take a look at in making: relocation order.

Fixed monolog v2 controller arrangement.

Fixed return of callback as an incentive for DurationLimiter.

Changed

Added runtime data yield for seeders.

Added severe boundary to Illuminate\Foundation\Testing\TestResponse::assertJsonPath().

Added deletedAtColumn discretionary boundary to Foundation\Testing\Concerns\InteractsWithDatabase::assertSoftDeleted().

Moved along

Further developed AuthServiceProvider::registerEventRebindHandler() on the off chance that watchman isn't instated.

The Laravel team announced the immediate availability of Laravel v6.1.0 with a new eager() method added to Lazy Collections along with the latest updates for Laravel 6.

LazyCollections—a new feature added to Laravel 6—now has an eager() method that “enumerates all of the lazy collection’s values, and constructs a new LazyCollection instance, which will now be backed by an array.”

You can see the full list of new features and updates below, and the whole diff between 6.0.4 and 6.1.0 on GitHub. The full release notes for Laravel 6.0 are available in the GitHub v6 changelog:

Lazy Collection in Laravel or overall concept:

The lazy collection works for big datasets like multi-gigabyte file sizes. For Example, if you want to read data from a big size file it can exceed your memory size. SO lazy collections can be used for your reading the data from your file in small parts.

The Laravel cursor method on Eloquent ORM gives us the lazy collection. The cursor behind the scene uses the PHP generator.

Laravel cursor gives us lazy collections

LazyCollection::make(function () { } ) also create lazy collections

Flight::lazy() also give us lazy collections.

the lazy method returns a flattened LazyCollection of Eloquent models.

End:

Laravel's Eager Lethargic Assortment is an integral asset that permits you to handle all information with very little memory. Consequently, attempt to gain proficiency with the course of combination and begin involving it in your client's venture.

tech news
1

About the Creator

Tina Modi

Laravel Developer at PHPDots Technologies

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.