# Memoized Cache Driver
12.9 新增 memo cache driver,可以對 cache 在做一層 memory cache,比如第一次從 Redis cache 撈,但在同一個 req 當中,之後都可從 PHP Process memory 當中撈
<?php
Cache::get('foo'); // hits the cache
Cache::get('foo'); // hits the cache
Cache::get('foo'); // hits the cache
Cache::memo()->get('foo'); // hits the cache
Cache::memo()->get('foo'); // does not hit the cache
Cache::memo()->get('foo'); // does not hit the cache
# Freeze Time Test Updates
12.9,freeTime() & freeSecond() 會 return date
<?php
// Before
$now = now();
Carbon::setTestNow($now);
$post->slug = $slug;
$post->save();
$package->refresh();
$this->assertTrue($now->equalTo($post->updated_at));
// After
$now = $this->freezeSecond();
$post->slug = $slug;
$post->save();
$package->refresh();
$this->assertTrue($now->equalTo($post->updated_at));
# Add a Callback for DB Transaction Failures
12.9,DB::transaction() 可以帶入 closure,fails 時觸發
<?php
DB::transaction(
callback: function () {
// do DB stuff
},
onFailure: function () {
Notification::send($admin, new SomethingImportantBroke());
}
);
# Model Relationship Autoloading from a Model
12.9,可以 enable lazy eager load all relationships of 特定 model
<?php
// Before
$post->tags->withRelationshipAutoloading();
$post->authors->withRelationshipAutoloading();
// After
$post->withRelationshipAutoloading();
# Add Descriptive Error Messages to assertViewHas()
12.9,assertViewHas() 有更完整的 error message
<?php
# Before
1) Tests\Feature\App\Http\CustomerControllerTest::a_test_example
Failed asserting that false is true.
# After
1) Tests\Feature\App\Http\CustomerControllerTest::a_test_example
Failed asserting that 'key_with_value' matches the expected value.
Failed asserting that 0 matches expected 10.
# Fluent make() Method
12.9,新增 Fluent::make() 來建立 Fluent instance
<?php
use Illuminate\Support\Fluent;
$instance = Fluent::make($attributes);