Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the additions, fixes and changes to Laravel 9.5?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what are the additions, fixes and changes of Laravel 9.5 version". In daily operation, I believe many people have doubts about the addition, repair and change of Laravel 9.5 version. I have consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the new, fixed and changed Laravel 9.5 versions?" Next, please follow the editor to study!

The Laravel team released version 9.5, including partial queue forgery, freezeTime () helper function, storing assertDirectoryEmpty () assertions, closures in assertJsonPath (), and so on:

Callback support for collection Implode methods

@ Lito contributed callback support on Collect::implode () to simplify the-> map ()-> implode () call:

/ / before {{$user- > cities- > map (fn ($city) = > $city- > name.' ('. $city- > state- > name.')')-> implode (',')}} / / use callback {{$user- > cities- > implode (fn ($city) = > $city- > name.' ('. $city- > state- > name.')',',')} to assert an empty directory using Storage Fake

Mark Beech contributes to the ability to assert an empty directory using the Storage::fake () instance:

/ / before version 9.5, $this- > assertEmpty (Storage::disk ('temp')-> allFiles (' / foo')); / / + 9.5Storage::disk ('temp')-> assertDirectoryEmpty (' / foo')

If there are no files in the directory, only other subdirectories, the assertion will fail because it contains other folders / files. Here is an example from pull request discussion:

Storage::fake ('temp'); Storage::disk (' temp')-> put ('/ foo/bar.txt', 'string'); Storage::disk (' temp')-> assertDirectoryEmpty ('/'); / / failed JSON assertion "assertJsonPath ()" now accepts closures

Fabien Villepinte contributes to the ability to pass closures to assertJsonPath without any backward compatible interrupts:

$response = TestResponse::fromBaseResponse (new Response (['data' = > [' foo' = > 'bar'],])); $response- > assertJsonPath (' data.foo', 'bar'); $response- > assertJsonPath (' data.foo', fn ($value) = > $value = = 'bar')

Although the above example seems easier to use the string version, if you need to assert more complex logic around the path, you can now use closures.

Partial queue forgery

Taylor Otwell contributed some forgery to the queues in the test:

Queue::fake ([JobsToFake::class, / *... * /]); A new way to create a "through" model

Hafez Divandari contributes to the ability to create a new "through" model without covering the entire hasOneThrough or hasManyThrough method:

/ / Define a `newThroughInstance` methodprotected function newThroughInstance ($resource) {return (new\ App\ Models\ ExampleEntity)-> setTable ($ThroughInstance`);} Helper function for new string wrapping

Markus Hebenstreit contributes the wrap () string helper function. Here is a sample usage from pull request description:

Str:wrap ('value')-> wrap (' "); Str::of ('value')-> wrap ('"); str ('value')-> wrap (' "'); / / output:" value "Str:wrap ('is',' This', 'metered'); Str::of ('is')-> wrap (' This', 'metered'); str ('is')-> wrap (' This', 'meteoric'); / / output: This is me! Freeze Time helper functions for testing

@ Italo contributes the freezeTime () helper function-- a test method that freezes the current time in the test:

Public function test_something () {$this- > freezeTime (); / or set the time to the current second of the date / / with no subsecond precision. $this- > freezeSecond ();}

The freezeTime () method is the syntactic sugar of:

$this- > travelTo (Carbon::now ()); allows callable objects to be accepted in Http::beforeSending ()

Dries Vints helps to accept callable objects in the Http::beforeSending () method, not just callable classes. Now, the following example will work instead of getting "call the member function on the array _ _ invoke ()":

Http::baseUrl ('https://api.example.org')-> beforeSending ([$this,' prepareRequest'])-> asJson ()-> withoutVerifying (); release notes

You can see the complete list of new features and updates below, as well as the differences between 9.4.0 and 9.5.0 on GitHub. The following release notes come directly from changelog:

Version 9.5.0

Add

Added callback support for implode collection methods. (# 41405)

Added Illuminate/Filesystem/FilesystemAdapter::assertDirectoryEmpty (). (# 41398)

Implement mail "metadata" for SesTransport. (# 41422)

Make assertPath () accept the closure. (# 41409)

Added callable support for operatorForWhere on the collection. (# 41414, # 41424)

Some queue forgery has been added. (# 41425)

Added the-name option for the schedule:test command. (# 41439)

Illuminate/Database/Eloquent/Concerns/HasRelationships::newRelatedThroughInstance () is defined. (# 41444)

Added Illuminate/Support/Stringable::wrap () (# 41455)

The "freezeTime" helper function has been added for testing. (# 41460)

Allow the use of beforeSending calls in Illuminate/Http/Client/PendingRequest.php::runBeforeSendingCallbacks (). (# 41489)

Repair

Fixed deprecation warning from route:list when filtering names or domains. (# 41421)

Fixed HTTP::pool response when URL returned null status code. (# 41412)

Fixed recaller name resolution in Illuminate/Session/Middleware/AuthenticateSession.php. (# 41429)

Fixed guard instances used in / Illuminate/Session/Middleware/AuthenticateSession.php (# 41447)

Fixed route:list-except-vendor to hide Route::view () & Route::redirect () (# 41465)

Change

Add an empty type for the connection property in\ Illuminate\ Database\ Eloquent\ Factories\ Factory. (# 41418)

Updated reserved name in GeneratorCommand (# 41441)

The php artisan schedule:list command is redesigned. (# 41445)

Eloquent high-order proxy properties are extended. (# 41449)

Allows you to pass named parameters to a dynamic local scope. (# 41478)

If the label passes but is not supported in Illuminate/Encryption/Encrypter.php, an exception is thrown. (# 41479)

Update the PackageManifest::$vendorPath initialization for the case when the composer vendor folder is not in the project folder. (# 41463)

At this point, the study of "what are the new, fixed and changed versions of Laravel 9.5" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report