0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel 12 の新公開APIについて調べてみた

Posted at

詳細フルリファレンスは自サイトで公開しています
👉 https://mikaduki.info/laravel/laravel12-public-api-ref


この記事でやること

  • Laravel 12 に追加された 公開 API 21 本ざっくり 紹介
  • 「これ気になる!」と思ったら ↑ リンク先 で完全サンプル&検証コードをチェックできるようにする
  • 元記事に新機能をTestしたPestコードがあります

新 API ダイジェスト

Tag API ひとことで
12.1.0 Arr::partition() 真偽で 2 分割
12.1.0 Context::scope() 一時スコープ実行
12.2.0 Context::increment() / decrement() 数値を ±N
12.4.0 Arr::sole() 単一ヒット取得
12.4.0 QueueFake::listenersPushed() キュー済リスナー数
12.6.0 Rules\Password::appliedRules() パスワード制約確認
12.6.0 Model::fillAndInsert() 一括 fill→insert
12.6.0 Http::failedRequest() 直近の失敗取得
12.8.0 Collection::fromJson() JSON→Collection
12.10.0 Fluent + Conditionable when/unless チェイン
12.13.0 TestResponse::assertRedirectBack() 戻りリダイレクト検証
12.14.0 Context::except() 指定キー除外
12.14.0 Context::exceptHidden() 隠しキー除外
12.14.0 Arr::from() iterable→配列
12.15.0 TestResponse::assertClientError() 4xx 検証
12.15.0 TestResponse::assertRedirectToAction() アクション遷移検証
12.16.0 Arr::hasAll() 全キー存在判定
12.16.0 Rule::contains() 配列値包含バリデーション
12.16.0 Stringable::toUri() URL エンコード
12.19.0 TestResponse::assertRedirectBackWithErrors() エラー付き戻り検証

🧩 配列 & 文字列系

// Arr::partition — 偶数と奇数に分けるだけで地味に便利
[$even,$odd] = Arr::partition([1,2,3,4], fn($v)=>$v%2===0);

// Arr::sole — 「唯一を取りたい」時の安全版 find()
$user = Arr::sole($users, fn($u)=>$u['id']===42);

// Arr::hasAll — Config チェックの if 連発とおさらば
if (Arr::hasAll($payload, ['name','email'])) {
    // all good
}

// Arr::from — コレクションを即座に生配列へ
Arr::from(collect(['a','b'])); // ['a','b']

// Stringable::toUri — UI で使うとき地味に書きやすい
$url = Str::of('Hello World!')->toUri(); // Hello%20World!

配列関数以外も本記事でコード付き紹介してますので、良かったら見に来てください!
👉 https://mikaduki.info/laravel/laravel12-public-api-ref

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?