LoginSignup
2
1

More than 3 years have passed since last update.

【Laravel】条件付きで必須チェックの組み合わせを実現する。

Posted at

「hoge 且つ fuga()」 が真の時に、hogeの必須チェックを有効にする


    /**
     * 条件付き必須チェックの組み合わせを実現。
     * @param Validator $validator
     */
    public function withValidator(Validator $validator)
    {
        // 「hoge 且つ fuga」の時には必須チェックを有効にする
        $validator->sometimes('hoge', ['nullable', $this->fuga()], function ($o) {
            return $o->hoge == true;
        });
    }
2
1
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
2
1