When you need to validate a field, but don't actually require it for anything e.g. 'accept terms and conditions', make use of the exclude
rule. That way, the validated
method won't return it...
1class StoreRequest extends FormRequest 2{ 3 public function rules(): array 4 { 5 return [ 6 'name' => 'required|string', 7 'email_address' => 'required|email', 8 'terms_and_conditions' => 'required|accepted|exclude', 9 ];10 }
1class RegistrationController extends Controller 2{ 3 public function store(StoreRequest $request) 4 { 5 $payload = $request->validated(); // only name and email 6 7 $user = User::create($payload); 8 9 Auth::login($user);10 11 return redirect()->route('dashboard');12 }
Tip given by @mattkingshott