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"]
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), ); }
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), ); }
For more information, please see the pull request about this feature and the description and discussion of this feature.
@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');
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:'), ], ],
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());
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));
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:
Illuminate/View/Factory::renderUnless()
(#40077)Illuminate/Filesystem/FilesystemManager::setApplication()
(#40058)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!