Our Global Presence
Canada
57 Sherway St,
Stoney Creek, ON
L8J 0J3
India
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
USA
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
Before we move directly to talk about 7.4 release, let’s go through each of the earlier minor releases of Laravel 7.
We will briefly look at the new features in the 7.1 release, which introduced a convenient API resource method to work with new route caching in Laravel 7.x and the ability to customize the constrained table name.
Lasse Rafn contributed an apiResource()
convenience method to work with the new Laravel 7.x caching.
Since Laravel 7.X has a new (optimized) routing implemented, route names are more important, and caching routes will break if naming collisions happen.
Normally you can use Route::name(‘posts’)->resource(…… to change the name of a group (useful for nested routes like: /posts/{post}/comments).
However, this is not possible with apiResource
.
We propose this change to allow that. It’s just a convenience to replace:
/ Before Route::name('posts') ->resource( 'posts/{post}/comments', 'PostCommentsController' ) ->only([ 'index', 'show', 'store', 'update', 'destroy' ]); // Using the apiResource() method Route::name('posts') ->apiResource( 'posts/{post}/comments', 'PostCommentsController' );
Samuel França contributed the ability to pass a table name to the constrained() method in the ForeignIdColumnDefinition class:
Here’s one example from the tests:
$blueprint ->foreignId('team_column_id') ->constrained('teams');
This version was released with HTTP client query string support and a new timeout configuration option for the SMTP mail driver. Let’s check out the new features real quick!
ShawnCZek contributed the expectsConfirmation()
method on the PendingCommand class used to test artisan commands:
$this->artisan('foo:bar') ->expectsConfirmation('Do you want to continue?', 'no') ->assertExitCode(1);
The confirmation assertion uses expectsQuestion under the hood, but asserts the actual value from the test. The same above would originally need to be:
$this->artisan('foo:bar') ->expectsConfirmation('Do you want to continue?', true) ->assertExitCode(1);
Markus Podar contributed a timeout configuration for the SMTP mail driver. The default is 30 seconds. If you want to tweak the default, add a custom timeout configuration in seconds:
'timeout' => 60, // seconds
Irfaq Syed contributed query string support to the Laravel HTTP Client, meaning you can pass a second argument to Http::get():
Here’s an example of how it works:
Http::get('https://example.com/get'); // URL: https://example.com/get Http::get('https://example.com/get?abc=123'); // URL: https://example.com/get?abc=123 Http::get('https://example.com/get', ['foo' => 'bar']); // URL: https://example.com/get?foo=bar Http::get('https://example.com/get', 'foo=bar'); // URL: https://example.com/get?foo=bar
Note that passing query params to get() overrides any present in the URI, so use one or the other.
This version was released with the ability to use ^4.0 versions of ramsey/uuid. Since the release of Laravel 7.2, a few patch releases are available that we’ll briefly cover.
Laravel 7.3 adds the possibility to use ^4.0 of ramsey/uuid, but still supports v3.7 as well. The composer dependency is now ^3.7|^4.0.
Laravel 7.2.2 fixes a few blade component issues. Notably, the make:component
command now supports sub directories:
php artisan make:component Navigation/Item # previously creates the following: # View/Components/Navigation/Item.php # views/components/item.blade.php # Now creates them as expected: # View/Components/Navigation/Item.php # views/components/navigation/item.blade.php
Laravel 7 introduced route caching speed improvements, but with that have been a few issues with apps in-the-wild. Laravel 7.2.1 fixed a route naming issue with cache; you should upgrade to the latest 7.x release to get the newest routing fixes.
It’s important to note that you should ensure the uniqueness of route names, as routes with duplicate names can “cause unexpected behavior in multiple areas of the framework.”
The latest version is released with quite a few new features, such as a custom model caster interface, a “when” higher-order collection proxy, and the ability to clear an existing “order” from the query builder.
Custom model caster interface, a “when” higher-order collection proxy, and the ability to clear an existing “order” from the query builder are the new features of Laravel 7.4.
Loris Leiva contributed the ability to use a higher-order proxy with the Collection::when()
method:
// With this PR, this: $collection->when($condition, function ($collection) use ($item) { $collection->push($item); }); // ... can be refactored as this: $collection->when($condition)->push($item);
This PR enables you to chain other higher-order proxy methods:
// This: $collection->when($condition, function ($collection) { $collection->map->parseIntoSomething(); }); // ... can be refactored as this: $collection->when($condition)->map->parseIntoSomething();
Adrian Nürnberger contributed a console test method for asking choices.
Given the following example:
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $defaultIndex);
You could only assert the message of this question, but cannot test the given choices:
$this->artisan('question') ->expectsQuestion('What is your name?', 'Taylor') ->assertExitCode(0);
As of Laravel 7.4, you can now do the following:
$this->artisan('question') ->expectsChoice('What is your name?', 'Taylor', ['Taylor', 'Dayle']) ->assertExitCode(0);
You can also guarantee the order of choices by passing a fourth boolean argument:
$this->artisan('question') ->expectsChoice('What is your name?', 'Taylor', ['Taylor', 'Dayle'], true) ->assertExitCode(0);
@nihilsen contributed the ability to define default props via @props:
<!-- Previously you might need something like: --> @props(['type', 'message']) @php $type = $type ?? 'info' @endphp <!-- New defaults in Laravel >=7.4 --> @props(['type' => 'info', 'message'])
Brent Roose contributed a Castable interface which allows “castable” types to specify their caster classes:
// Instead of this class ModelX extends Model { protected $casts = [ 'data' => CastToDTO::class . ':' . MyDTO::class, ]; } // You could do this class ModelY extends Model { protected $casts = [ 'data' => MyDTO::class, ]; } // The underlying class use Illuminate\Contracts\Database\Eloquent\Castable; class MyDTO implements Castable { public static function castUsing() { return CastToDTO::class . ':' . static::class; } }
Jonathan Reinink contributed a reorder() method to the query builder to reset orderBy()
calls:
$query = DB::table('users')->orderBy('name'); $unorderedUsers = $query->reorder()->get();
Reorder allows you to define default order in Eloquent relationships, with the ability to back out if needed:
class Account extends Model { public function users() { return $this->hasMany(User::class)->orderBy('name'); } } // Remove the name orderBy and order by email $account->users()->reorder()->orderBy('email'); // The same can be written as: $account->users()->reorder('email');
For more information and to develop web application using Laravel, Hire Laravel Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft”. To develop any custom web apps using Laravel, please visit our technology page.
Content Source:
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
© 2024 — HK Infosoft. All Rights Reserved.
© 2024 — HK Infosoft. All Rights Reserved.
T&C | Privacy Policy | Sitemap