Validate method on request
📖 Scenario: You are building a simple Laravel web application where users submit a form with their name and email. You want to make sure the data is valid before saving it.
🎯 Goal: Create a Laravel controller method that uses the validate method on the request to check that the name is required and at least 3 characters long, and the email is required and a valid email address.
📋 What You'll Learn
Create a controller method named
store that accepts a Request objectUse the
validate method on the $request to validate name and emailThe
name field must be required and have a minimum length of 3The
email field must be required and be a valid emailReturn a simple success message after validation
💡 Why This Matters
🌍 Real World
Validating user input is essential in web applications to prevent bad data and security issues.
💼 Career
Laravel developers frequently use the validate method on requests to enforce data rules before processing.
Progress0 / 4 steps