Home > PHP Framework > Laravel > body text

Laravel 8.77 is released, these features have been improved!

藏色散人
Release: 2022-01-22 09:08:45
forward
2133 people have browsed it

The following tutorial column of Laravel will introduce to you "Laravel 8.77 is released, these functions have been improved", I hope it will be helpful to everyone!

The Laravel team released version 8.77 with improvements to property conversions/accessors, requesting the date() method to access data as a DateTime instance, MAC address validation, the ability to define custom temporary URLs on storage disks, and Latest change branch in v8.x. [Recommended: "laravel video tutorial"]

Attribute conversion/accessor improvement

Taylor Otwell provides a new way to define attribute accessors and modifiers:

// 之前, 两个方法的方式
public function setTitleAttribute($value)
{
    $this->attributes['title'] = strtolower($value);
}
 // 新的方式
protected function title(): Attribute
{
    return new Attribute(
        set: fn ($value) => strtolower($value),
    );
}
Copy after login

Here is an example that implements both get and set:

/**
 * 获取用户的标题
 */
protected function title(): Attribute
{
    return new Attribute(
        get: fn ($value) => strtoupper($value),
        set: fn ($value) => strtolower($value),
    );
}
Copy after login

For more information, please see the pull request about this feature and the description and discussion of this feature.

Date time parsing has been added to the request instance

@Italo provides a date() method for the request instance, making it very easy to obtain the date instance from the request data Convenience:

// 以前
if ($date = $request->input('when')) {
    $date = Carbon::parse($datetime);
}
// 之后
$date = $request->date('when');
Copy after login

Per-connection prefixes

Ben Tidy helps to use prefixes on a per-connection basis in Predi. The following is an example of a pull request for a Redis configuration:

'redis' => [
    'client' => env('REDIS_CLIENT', 'predis'),
     'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
        'prefix' => env('REDIS_PREFIX', 'prefix:'),
    ],
     'cache' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_CACHE_DB', 1),
        'prefix' => env('REDIS_PREFIX', 'prefix2:'),
    ],
],
Copy after login

MAC address verification rules

Bilal Al-Massry contributed the mac_address verification rules for verifying MAC addresses:

$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['mac' => 'foo'], ['mac' => 'mac_address']);
$this->assertFalse($v->passes());
 $trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['mac' => '01-23-45-67-89-ab'], ['mac' => 'mac_address']);
$this->assertTrue($v->passes());
 $trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['mac' => '01-23-45-67-89-AB'], ['mac' => 'mac_address']);
$this->assertTrue($v->passes());
Copy after login

Defining Storage Temporary URL Method

Ash Allen contributed the ability to define custom temporary URL logic for the Storage facade. Here are a few examples of pull requests:

Storage::disk('local')
    ->buildTemporaryUrlUsing(function ($path, $expiration, $options) {
      return 'using local';
    });
 // $url is: 'using local'
$url = Storage::temporaryUrl('file.jpg', now()->addMinutes(5));
Copy after login

Release Notes

You can see the full list of new features and updates below on github and between 8.76.0 and 8.77.0 difference. The following release notes are taken directly from the changelog:

v8.77.0

New

  • Property Conversion/Accessor Improvements (#40022)
  • Added Illuminate/View/Factory::renderUnless() (#40077)
  • Add date and time parsing to the Request instance (#39945)
  • Make each connection Prefixes can be used on Predis (#40083)
  • Added rules to verify MAC addresses (#40098)
  • Added ability to define temporary URLs for storage (#40100)

Fixed

  • Fix the out of memory error that may occur when deleting values ​​from the cache by referencing the key in the Redis driver (#40039)
  • New Illuminate/Filesystem/FilesystemManager::setApplication() (#40058)
  • Fix parameter passing in doesntContain() method (739d847)
  • Translate Enum rule messages (#40089)
  • Fix validation for dates (#40088)
  • Does not allow models to be used with except in PruneCommand.php (f62fe66)

Changed

  • Use database explain command-specific functionality for Query\Builder:explain via the Eloquent\Query::explain method (#40075)

Original address: https://laravel-news.com/laravel-8-77-0

Translation address: https://learnku.com/laravel/t/64602

The above is the detailed content of Laravel 8.77 is released, these features have been improved!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!