Skip to main content
Quick Tip

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

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.