write ahead log

ロールフォワード用

Laravelのリクエストバリデーションで除外IDを指定する

unique使うと更新時に問題になるんだけど, ignoreというメソッドがいつの間にか追加されている.

これを使えば「更新対象レコードのidを除外してuniqueチェック」ができるけど, 更新対象レコードのidをフォームリクエスト内でどうやって取得するのかわからなかった.

結論的にはルートパラメータの値を指定すれば良いらしい.

こんなルートがある場合には

Route::post('/products/{product}', 'ProductsController@store')->name('products.store');

こんな風に指定できる

Rule::unique('products')
    ->ignore($this->product)
    ->where('first_name', $this->first_name)
    ->where('last_name', $this->last_name),