blocs/admin: 削除機能のカスタマイズ
blocs/admin: 削除機能のカスタマイズ
自動生成された管理画面の削除機能をカスタマイズする方法を説明します。確認画面の追加や処理前後の制御を調整できます。
前提条件: 自動生成ツールで管理画面を生成済みであること
テンプレートの一覧
| テンプレート名 | 用途 |
|---|---|
| include/show.html | 削除対象の項目を表示するパーツテンプレート |
| show.blocs.html | 削除確認画面のメインテンプレート |
処理フロー
初期状態では モーダル で削除確認・実行を行います(詳しくは No.1.2 / No.5.4)。confirmDestroy / confirmSelect ルートおよび専用確認画面テンプレートは自動生成に含まれません。専用確認画面を使う場合のみ、以下の「パターンB」のフローになります。セッションキー {viewPrefix}.confirm の共有や確定時の validate*() スキップについては No.4.2 を参照してください。
★ はオーバーライドによるカスタマイズポイントです。
単一削除フロー
パターンA: モーダル確認(デフォルト)
flowchart TD
index[index]
subgraph show["show — 削除対象の表示(UpdateTrait::show)"]
direction TB
s1["getCurrent ★ — データ取得"]
s2["prepareShow ★ — 表示データ準備(UpdateTrait)"]
s3["outputShow — 画面表示(UpdateTrait)"]
s1 --> s2 --> s3
end
modal["(モーダルで確認)"]
subgraph destroy["destroy — 削除処理"]
direction TB
d1["getCurrent ★ — データ取得"]
d2["validateDestroy ★ — 削除データの検証"]
d3["prepareDestroy ★ — 削除データ準備"]
d4["executeDestroy ★ — データ削除"]
d5["logDestroy ★ — ログ記録"]
d6["outputDestroy — 完了処理 → 一覧画面へ"]
d1 --> d2 --> d3 --> d4 --> d5 --> d6
end
index --> s1
s3 --> modal
modal --> d1
パターンB: 専用確認画面(任意・追加時)
flowchart TD
index[index]
subgraph show["show — 削除対象の表示"]
direction TB
s1["getCurrent ★ — データ取得"]
s2["prepareShow ★ — 表示データ準備"]
s3["outputShow — 画面表示"]
s1 --> s2 --> s3
end
subgraph confirm["confirmDestroy — 削除確認画面表示"]
direction TB
c1["getCurrent ★ — データ取得"]
c2["validateDestroy ★ — 削除データの検証"]
c3["prepareConfirmDestroy ★ — 表示データ準備"]
c4["outputConfirmDestroy — 確認画面表示"]
c1 --> c2 --> c3 --> c4
end
subgraph destroy["destroy — 削除処理"]
direction TB
d1["getCurrent ★ — データ取得"]
d2["validateDestroy ★ — 削除データの検証"]
d3["prepareDestroy ★ — 削除データ準備"]
d4["executeDestroy ★ — データ削除"]
d5["logDestroy ★ — ログ記録"]
d6["outputDestroy — 完了処理 → 一覧画面へ"]
d1 --> d2 --> d3 --> d4 --> d5 --> d6
end
index --> s1
s3 --> c1
c4 --> d1
一括削除フロー(SelectTrait)
パターンA: モーダル確認(デフォルト)
flowchart TD
index["index(チェックボックスで選択)"]
modal["(モーダルで確認)"]
subgraph select["select — 選択データ処理(一括削除)"]
direction TB
s1["validateSelect ★ — 選択データの検証"]
s2["prepareSelect ★ — 選択データ準備"]
s3["executeSelect ★ — 選択データ処理"]
s4["logSelect ★ — ログ記録"]
s5["outputSelect — 完了処理 → 一覧画面へ"]
s1 --> s2 --> s3 --> s4 --> s5
end
index --> modal
modal --> s1
パターンB: 専用確認画面(任意・追加時)
flowchart TD
index["index(チェックボックスで選択)"]
subgraph confirm["confirmSelect — 選択確認画面表示"]
direction TB
c1["validateSelect ★ — 選択データの検証"]
c2["prepareConfirmSelect ★ — 表示データ準備"]
c3["outputConfirmSelect — 確認画面表示"]
c1 --> c2 --> c3
end
subgraph select["select — 選択データ処理(一括削除)"]
direction TB
s1["validateSelect ★ — 選択データの検証"]
s2["prepareSelect ★ — 選択データ準備"]
s3["executeSelect ★ — 選択データ処理"]
s4["logSelect ★ — ログ記録"]
s5["outputSelect — 完了処理 → 一覧画面へ"]
s1 --> s2 --> s3 --> s4 --> s5
end
index --> c1
c3 --> s1
ベースコントローラーのメソッド
単一削除
| 可視性 | メソッド名 | 処理内容 |
|---|---|---|
| public | show | 削除対象の表示(UpdateTrait に定義。show.blocs.html を表示) |
| protected | prepareShow | 出力のためのデータ処理 |
| protected | outputShow | ビューの出力処理 |
| public | confirmDestroy | 確認画面を表示 |
| protected | validateDestroy | 削除前のバリデーション処理 ★ |
| protected | prepareConfirmDestroy | 出力のためのデータ処理 ★ |
| protected | outputConfirmDestroy | ビューの出力処理 |
| public | destroy | 削除処理を実行 |
| protected | prepareDestroy | 出力のためのデータ処理 ★ |
| protected | executeDestroy | データの削除処理 ★ |
| protected | outputDestroy | ビューの出力処理 |
専用の確認画面(パターンB)を使う場合は confirmDestroy ルートと confirmDestroy.blocs.html を追加してください(POST で定義)。一括削除の専用確認画面は confirmSelect ルートを追加します。
Route::post('/{id}/confirmDestroy', [UserController::class, 'confirmDestroy'])->where('id', '[0-9]+')->name('confirmDestroy');
Route::post('/confirmSelect', [UserController::class, 'confirmSelect'])->name('confirmSelect');
confirmDestroy / confirmSelect ルートも自動生成されません。
ベースコントローラーの主な変数
| 変数名 | 説明 |
|---|---|
$this->deletedNum |
削除されたデータの件数。削除操作の結果確認に使用 |
一括削除機能(SelectTrait)
一覧画面で複数のレコードを選択して一括削除する機能です。
メソッド
| 可視性 | メソッド名 | 処理内容 |
|---|---|---|
| public | confirmSelect | 選択内容のバリデーションと確認画面の表示 |
| protected | validateSelect | 選択項目のバリデーション($this->loopItem をチェック) ★ |
| protected | prepareConfirmSelect | 確認画面表示前のデータ処理 ★ |
| protected | outputConfirmSelect | 確認画面のビュー出力 |
| public | select | 一括削除処理の実行 |
| protected | prepareSelect | 削除前のデータ処理 ★ |
| protected | executeSelect | 選択されたレコードの一括削除 ★ |
| protected | outputSelect | 削除件数を含むリダイレクト処理 |
主な変数
| 変数名 | 説明 |
|---|---|
$this->selectedIdList |
選択されたレコードのID配列 |
$this->deletedNum |
削除されたレコードの件数 |