0
0
Laravelframework~30 mins

Available validation rules in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Available Validation Rules in Laravel
📖 Scenario: You are building a simple Laravel form to register users. You need to ensure the data entered is valid before saving it.
🎯 Goal: Create a Laravel validation array using common validation rules to check user input.
📋 What You'll Learn
Create an array called $rules with specific validation rules
Include rules for required fields, email format, minimum length, and numeric values
Use Laravel's built-in validation rule names exactly as specified
Add a custom rule for a password confirmation field
💡 Why This Matters
🌍 Real World
Validating user input is essential in web applications to ensure data integrity and security before saving to a database.
💼 Career
Understanding Laravel validation rules and how to apply them is a key skill for backend developers working with Laravel frameworks.
Progress0 / 4 steps
1
Create the validation rules array
Create a PHP array called $rules with these exact keys and rules: 'name' => 'required', 'email' => 'required|email', 'age' => 'nullable|numeric'.
Laravel
Need a hint?

Use Laravel's validation rule strings separated by pipes (|) for multiple rules.

2
Add password validation rules
Add to the $rules array the keys 'password' with rules 'required|min:8' and 'password_confirmation' with rule 'required|same:password'.
Laravel
Need a hint?

Use min:8 to require at least 8 characters and same:password to confirm the password.

3
Use the validation rules in a controller method
Inside a Laravel controller method, write the line $validatedData = $request->validate($rules); to apply the validation rules.
Laravel
Need a hint?

Use the validate method on the $request object with the $rules array.

4
Complete the controller method with data saving
Add the line User::create($validatedData); after validation to save the user data, assuming the User model is imported.
Laravel
Need a hint?

Use the User::create() method to save the validated data to the database.