Laravel 5.7 - What’s New Features in Laravel 5.7?

by jay patel




What's new in 5.7? What improvements were made? Learn how to build better PHP applications with this new release. In this article, I'll cover the new features in Laravel 5.7 and several other changes and deprecations.

5.7.18 Released

Laravel 5.7.18 is available in December 2018 with the latest updates to the Laravel framework v5.7.

First, the framework now replaces all placeholders for the
starts_with validation rule introduced in Laravel 5.7.15.

A new Facade::resolved() method registers callbacks that are called after service resolution. Here’s an example provided in the pull request:

 

/**

* Register the token guard.

*

* @return void

*/

protectedfunction  registerGuard ( )

{

Auth : : resolved ( function ( $auth )  {

$auth -> extend ( ' passport ' , function ( $app ,  $name ,  array  $config )  {

return  tap ( $this -> makeGuard ( $config ) ,  function  ( $guard )  {

$this -> app -> refresh ( ' request ' ,  $guard ,  ' setRequest ' ) ;

} ) ;

} ) ;

} ) ;

}

 

 

The last new feature is an env variable APP_CONFIG_CACHE to control the cache config path.

You can see the full list of fixes and the full diff between 5.7.17 and 5.7.18  on GitHub. 

Laravel 5.7.19 Released

Laravel 5.7.19 is available in December 2018 with a new
whereBetween collection method. This version also reverts a change to app()->call() introduced in Laravel 5.7.18
.

A new Collection::whereBetween() provides a way to filter collections between two values. Here’s an example from the pull request’s tests:

 

$c = new Collection ( [

' v ' => ] , 

' v ' => ] ,

' v ' => ] ,

' v ' => ' 3 ' ] ,

' v ' => ]

] ) ;

$this->assertEquals( 

[

' v ' => ] ,

' v ' => ] ,

' v ' => ' 3 ' ] ,

' v ' => ]

] ,

$c - > whereBetween ( ' v ' , [ , 4] ) -> values ( ) -> all ( )

) ;

 

 

The whereBetween method’s second argument felt a bit weird to me at first. However, the first array value is the lower bound (>=) and the second array value is the upper (<=).

You can see the full list of fixes and the full diff between 5.7.18 and 5.7.19 on GitHub. 

Laravel 5.7.20 Released

The Laravel team released 5.7.20 in January 2019 with added
chunkById() support on model relations, a new collection method, and some new FilesystemAdapter assertion methods.

First, you can now call chunkById() on related models in  BelongsToMany  and HasManyThrough relations:

 

 

$user -> articles ( ) -> chunkById ( 1,  function ( Collection  $collection ) {

// ...

} ) ;

 

 

Next, a new whereNotBetween collection method is useful to filter collection items not between a given range:

 

 

$filtered  =  $collection -> whereNotBetween ( ' price ' ,  [ 100, 200 ] ) ;

 

 

In the above example, items greater than 200 or less than 100 get returned in a filtered collection instance. The condition does not include the upper and lower boundaries, so in our example items that are exactly 100 or 200 are not included.

Next, you can allow predefined log channels to change the formatter via the configuration. Check out PR #26895 for further details.

The FilesystemAdapter storage assertions are now chainable and can handle multiple files at once:

 

 

Storage : : disk ( ' local ' )

-> assertExists ( [

$path,

$anotherPath,

] )

->assertMissing ( [

$yetAnotherPath,

$oneMoreFilePath,

] ) ;

 

 

You can now access the current route’s original bound parameters:

 

 

// A single param

$route -> originalParameter ( ' name ' )  ;

// All  params

$route -> originalParameters ( ) ;

 

 

The last new feature is pushedJobs() method on the QueueFake fake to retrieve all the jobs pushed to the queue during a test.

You can see the full list of fixes and the whole diff between 5.7.19 and 5.7.20 on GitHub.

Laravel 5.7.21 Released

The Laravel team released 5.7.21 15 Jan 2019 with miscellaneous fixes and changes.

First, the PendingCommand  class from the foundation testing will now re-throw a NoMatchingExpectationException to avoid the following undefined variable error when the exception method name doesn’t equal askQuestion:

 

 

ErrorException  :  Undefined  variable :  exitCode

 

 

Check PR #27158 for further details on this change, but it should have minimal impact on your existing projects.

Next, a few instances of get_called_class() function calls were replaced with static::class. The get_called_class() function might possibly get deprecated in PHP 7.4—at the time of writing the RFC is still a proposal.

Some fixes were also part of this release:

First, the Blueprint::removeColumn() fixes a bug which made it impossible to delete a column from a Blueprint instance.

You can now set BROADCAST_DRIVER=null as outlined in the broadcasting documentation. Previously, setting the driver to null would cause an InvalidArgumentException exception with the message “Broadcaster [] is not defined.”

A fix for assertSessionDoesntHaveErrors() was added for tests failing when the test response doesn’t have any errors. Previously, this assertion would fail with no errors were present at all causing a “Call to member function getBag() on null” error.

Last, a revert was made to reverse double localized strings in the 403.blade.php file.

Users of Laravel 5.7 should upgrade to get the latest changes and fixes.

You can see the full list of fixes and the whole diff between 5.7.20 and 5.7.21on GitHub.



Leave a Reply

Your email address will not be published. Required fields are marked *

   Confirm you are not a spammer
   Notify me of follow-up comments by email.