# Encrypt and decrypt Str helper methods

12.18 支援 fluent string chain

<?php
// Before
$encryptedToken = str('secret-api-token')
->pipe(fn(Stringable $str) => encrypt($str->value()))
->prepend('encrypted:')
->append(':end');


// After
$encryptedToken = str('secret-api-token')
->encrypt()
->prepend('encrypted:')
->append(':end');

# A command option for making batchable jobs

12.18 新增 command option,可直接建立 batchable job

php artisan make:job ProcessPodcast --batched
<?php
namespace App\Jobs;

use Illuminate\Bus\Batchable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class ProcessPodcast implements ShouldQueue
{
use Batchable, Queueable;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
if ($this->batch()->cancelled()) {
// The batch has been cancelled...

return;
}

//
}
}

# Configure a policy using a PHP Attribute

12.18 可使用 Attribute 来定指定 model 使用哪一个 policy

<?php
#[UsePolicy(PostPolicy::class)]
class Post extends Model {}

# Allow setting the RequestException truncation limit per request

Laravel 预设 truncate to 120 characters exception message,12.18 新增 method truncateRequestExceptionsAt() 来指定要保留多少 characters

<?php
Http::truncateExceptionsAt(240)->post(/* ... */)

# 参考来源

Laravel News