rules() { if(request() ->isMethod('post')){ $password = 'required' } else if(request() ->isMethod('put')) { $password = 'sometimes' } return [ 'password' => [$password, Rules\Passwod:defaults()] // or 'password' => [Rule::when(request()->isMethod('POST'), 'required'), Rule::when(request()->isMethod('PUT'), 'optional'), 'confirmed', Rules\Passwod:defaults() ] ] } protected function prepareForValidation() { if($this->password == null) { $this->request->remove('password') } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter