Published in
2 min readJul 29, 2024
# before and after Collection Methods
11.11 加入 before & after method,如下 example
<?php
$collection = collect([1, 2, 3, 4, 5, 'name' => 'taylor', 'framework' => 'laravel']);
$collection->before(2) // 1
$collection->before('taylor') // 5
$collection->before('laravel') // 'taylor'
$collection->before(fn ($value) => $value > 4) // 4
$collection->before(fn ($value) => ! is_numeric($value)) // 5
$collection->before(1) // null
$collection->before('not found') // null
$collection = collect([1, 2, 3, 4, 5, 'name' => 'taylor', 'framework' => 'laravel']);
$collection->after(1) // 2
$collection->after('taylor') // 'laravel'
$collection->after(fn ($value) => $value > 4) // 'taylor'
$collection->after(fn ($value) => ! is_numeric($value)) // 'laravel'
$collection->after('laravel') // null
$collection->after('not found') // null
# #Cache Events
11.11 新增了一些 cache event
<?php
use Illuminate\Cache\Events\ForgettingKey;
use Illuminate\Cache\Events\KeyForgetFailed;
use Illuminate\Cache\Events\KeyWriteFailed;
// Two public properties: `$this->value` and `$this->seconds`
use Illuminate\Cache\Events\RetrievingKey;
use Illuminate\Cache\Events\RetrievingManyKeys;
// One public property: `$this->keys`
use Illuminate\Cache\Events\WritingKey
// Two public properties: `$this->value` and `$this->seconds`
use Illuminate\Cache\Events\WritingManyKeys;
// Three public properties:
// `$this->keys`, `$this->values` and `$this->seconds`
# Support Third-party Relations in model:show
11.11 新增 model:show
command 可以看到 third party relation 資訊,細節參考 RP
# Session ID Getter
11.11 新增 Session::id()
<?php
Session::id();
// You can still use `getId()` too:
Session::getId();
# Timezone and Locale Added to the about Command
11.11 在 artisan about
command 中加入 Locale & Timezone 資訊
# Add Relation::getMorphAlias() Method
11.11 新增 Relation::getMorphAlias()
method,主要用在 test,開發者不需要再去找當初定義的 Alias name
<?php
$this->assertDatabaseHas('taskables', [
'taskable_type' => Relation::getMorphAlias(Document::class),
'taskable_id' => $mitigation->id,
'task_id' => $taskB->id
]);