Exclude validation value

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...

class StoreRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => 'required|string',
'email_address' => 'required|email',
'terms_and_conditions' => 'required|accepted|exclude',
];
}
class RegistrationController extends Controller
{
public function store(StoreRequest $request)
{
$payload = $request->validated(); // only name and email
 
$user = User::create($payload);
 
Auth::login($user);
 
return redirect()->route('dashboard');
}

Tip given by @mattkingshott

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 68 courses (1183 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses