crudスタイルなのが必須です。
storeアクション
public function rules(): array
{
// 重複をvalidate塩ます。
return [
'code' => ['required', 'string', 'max:10', 'unique:symbols,code'],
'name' => ['required', 'string', 'max:255', 'unique:symbols,name'],
];
}
updateアクション
public function rules(): array
{
// 自分以外のレコードに対して重複をvalidateします。
return [
'code' => ['required', 'string', 'max:10', 'unique:symbols,code,' . $this->route('id')],
'name' => ['required', 'string', 'max:255', 'unique:symbols,name,' . $this->route('id')],
];
}
特にupdateアクションでのコードですが、route(‘id’)から暗黙的にRequestを取得しているようですね。
便利すぎるwww
投稿者プロフィール
最新の投稿
プログラム2025年5月18日Laravelのvalidation、重複を避けるには?
ぼやき2025年5月18日コーディングやDBにはいつまで日本語が使えないのか。
ぼやき2025年5月16日class=”h1″とかの落とし穴?
ぼやき2025年5月14日requirements.txtに@ file:///croot とか入ってinstallに失敗する