search
HomePHP FrameworkLaravelSummarize the new additions, fixes and changes in Laravel 9.5 version!

This article brings you relevant knowledge about laravel. The Laravel team released version 9.5, which includes partial queue forgery, freezeTime() auxiliary function, storage assertDirectoryEmpty() assertion, etc., I hope everyone has to help.

Summarize the new additions, fixes and changes in Laravel 9.5 version!

[Related recommendations: laravel video

Laravel team released version 9.5, which includes partial queue forgery, freezeTime () Helper functions, storage assertDirectoryEmpty () assertions, closures in assertJsonPath (), etc.:

Callback support for the collection's Implode method

@Lito contributed on Collect::implode() Callback support to simplify ->map()->implode() calls:

// 之前<br/>{{ $user->cities->map(fn ($city) => $city->name.&#39; (&#39;.$city->state->name.&#39;)&#39;)->implode(&#39;, &#39;) }}<br/>// 使用回调 <br/>{{ $user->cities->implode(fn ($city) => $city->name.&#39; (&#39;.$city->state->name.&#39;)&#39;, &#39;, &#39;) }}<br/>

Using Storage Fake to assert an empty directory

Mark Beech contributed using Storage::fake () Example of the ability to assert an empty directory:

// 9.5 版本之前<br/>$this->assertEmpty(Storage::disk(&#39;temp&#39;)->allFiles(&#39;/foo&#39;));<br/>// +9.5<br/>Storage::disk(&#39;temp&#39;)->assertDirectoryEmpty(&#39;/foo&#39;);<br/>

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

Storage::fake(&#39;temp&#39;);<br/>Storage::disk(&#39;temp&#39;)->put(&#39;/foo/bar.txt&#39;, &#39;string&#39;);<br/>Storage::disk(&#39;temp&#39;)->assertDirectoryEmpty(&#39;/&#39;); // 失败<br/>

JSON assertion "assertJsonPath ()" now accepts closures

Fabien Villepinte contributed passing closures to assertJsonPath without any backwards Compatible interrupt capabilities:

$response = TestResponse::fromBaseResponse(new Response([<br/>    &#39;data&#39; => [&#39;foo&#39; => &#39;bar&#39;],<br/>]));<br/>$response->assertJsonPath(&#39;data.foo&#39;, &#39;bar&#39;);<br/>$response->assertJsonPath(&#39;data.foo&#39;, fn ($value) => $value === &#39;bar&#39;);<br/>

While the example above seems simpler using the string version, if you need more complex logic around path assertions, you can now use closures.

Partial Queue Faking

Taylor Otwell contributed partial faking to the queue under test:

Queue::fake([JobsToFake::class, /* ... */]);<br/>

A new way to create a “through” model

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

// Define a `newThroughInstance` method<br/>protected function newThroughInstance($resource)<br/>{<br/>    return (new \App\Models\ExampleEntity)->setTable($resource);<br/>}<br/>

New string wrap helper function

Markus Hebenstreit contributed wrap() String helper functions. Here's an example usage from the pull request description:

Str:wrap(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>Str::of(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>str(&#39;value&#39;)->wrap(&#39;"&#39;);<br/>// 输出: "value"<br/>Str:wrap(&#39;is&#39;, &#39;This &#39;, &#39; me!&#39;);<br/>Str::of(&#39;is&#39;)->wrap(&#39;This &#39;, &#39; me!&#39;);<br/>str(&#39;is&#39;)->wrap(&#39;This &#39;, &#39; me!&#39;);<br/>// 输出: This is me!<br/>

Freeze Time helper function for testing

@Italo contributed the freezeTime() helper function - one that will freeze the current time in the test Time test method:

public function test_something()<br/>{<br/>    $this->freezeTime();<br/>    // 或将时间设置为日期的当前秒<br/>    // 没有亚秒级精度。<br/>    $this->freezeSecond();<br/>}<br/>

freezeTime() method is syntactic sugar for the following:

$this->travelTo(Carbon::now());<br/>

Allows callable objects to be accepted in Http::beforeSending ()

Dries Vints help to accept callable objects in the Http::beforeSending() method, not just callable classes. The following example will now work instead of getting "call member function __invoke() on an array":

Http::baseUrl(&#39;https://api.example.org&#39;)<br/>    ->beforeSending([ $this, &#39;prepareRequest&#39; ])<br/>    ->asJson()<br/>    ->withoutVerifying();<br/>

Release Notes

You can check out the full list of new features and updates below And check out the differences between 9.4.0 and 9.5.0 on GitHub. The following release notes are taken directly from the changelog:

9.5.0 Version

New

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

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

  • Implements email "metadata" for SesTransport. (#41422)

  • Make assertPath () accept a closure. (#41409)

  • Added callable support for operatorForWhere on collections. (#41414, #41424)

  • Added some queue forgery. (#41425)

  • Added –name option to schedule:test command. (#41439)

  • defines Illuminate/Database/Eloquent/Concerns/HasRelationships::newRelatedThroughInstance(). (#41444)

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

  • Added "freezeTime" auxiliary function for testing. (#41460)

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

Fix

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

  • Fixed HTTP::pool response when URL returns empty status code. (#41412)

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

  • Fixed guard instance being used in /Illuminate/Session/Middleware/AuthenticateSession.php (#41447 )

  • ##Fixed route:list –except-vendor for hiding Route::view () & Route::redirect () (

    #41465)

Change

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

    #41418)

  • Updated reserved names in GeneratorCommand (

    #41441)

  • Redesigned the php artisan schedule:list command. (

    #41445)

  • Extended eloquent high-order proxy properties. (

    #41449)

  • Allows passing named parameters to dynamic local scopes. (

    #41478)

  • Throws an exception if the tag passes but is not supported in Illuminate/Encryption/Encrypter.php. (

    #41479)

  • When the composer vendor folder is not in the project folder, Update PackageManifest::$vendorPath is initialized for the case. (

    #41463)

[Related recommendations:

laravel video tutorial]

The above is the detailed content of Summarize the new additions, fixes and changes in Laravel 9.5 version!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
Using Laravel: Streamlining Web Development with PHPUsing Laravel: Streamlining Web Development with PHPApr 19, 2025 am 12:18 AM

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

Laravel: An Introduction to the PHP Web FrameworkLaravel: An Introduction to the PHP Web FrameworkApr 19, 2025 am 12:15 AM

Laravel is a modern PHP framework that provides a powerful tool set, simplifies development processes and improves maintainability and scalability of code. 1) EloquentORM simplifies database operations; 2) Blade template engine makes front-end development intuitive; 3) Artisan command line tools improve development efficiency; 4) Performance optimization includes using EagerLoading, caching mechanism, following MVC architecture, queue processing and writing test cases.

Laravel: MVC Architecture and Best PracticesLaravel: MVC Architecture and Best PracticesApr 19, 2025 am 12:13 AM

Laravel's MVC architecture improves the structure and maintainability of the code through models, views, and controllers for separation of data logic, presentation and business processing. 1) The model processes data, 2) The view is responsible for display, 3) The controller processes user input and business logic. This architecture allows developers to focus on business logic and avoid falling into the quagmire of code.

Laravel: Key Features and Advantages ExplainedLaravel: Key Features and Advantages ExplainedApr 19, 2025 am 12:12 AM

Laravel is a PHP framework based on MVC architecture, with concise syntax, powerful command line tools, convenient data operation and flexible template engine. 1. Elegant syntax and easy-to-use API make development quick and easy to use. 2. Artisan command line tool simplifies code generation and database management. 3.EloquentORM makes data operation intuitive and simple. 4. The Blade template engine supports advanced view logic.

Building Backend with Laravel: A GuideBuilding Backend with Laravel: A GuideApr 19, 2025 am 12:02 AM

Laravel is suitable for building backend services because it provides elegant syntax, rich functionality and strong community support. 1) Laravel is based on the MVC architecture, simplifying the development process. 2) It contains EloquentORM, optimizes database operations. 3) Laravel's ecosystem provides tools such as Artisan, Blade and routing systems to improve development efficiency.

Laravel framework skills sharingLaravel framework skills sharingApr 18, 2025 pm 01:12 PM

In this era of continuous technological advancement, mastering advanced frameworks is crucial for modern programmers. This article will help you improve your development skills by sharing little-known techniques in the Laravel framework. Known for its elegant syntax and a wide range of features, this article will dig into its powerful features and provide practical tips and tricks to help you create efficient and maintainable web applications.

The difference between laravel and thinkphpThe difference between laravel and thinkphpApr 18, 2025 pm 01:09 PM

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

Laravel user login function listLaravel user login function listApr 18, 2025 pm 01:06 PM

Building user login capabilities in Laravel is a crucial task and this article will provide a comprehensive overview covering every critical step from user registration to login verification. We will dive into the power of Laravel’s built-in verification capabilities and guide you through customizing and extending the login process to suit specific needs. By following these step-by-step instructions, you can create a secure and reliable login system that provides a seamless access experience for users of your Laravel application.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function