
Validation & Forms
Validation rules, form requests, custom rules, error messages, old input, CSRF protection, displaying errors
1Which method of a Form Request returns the validation rules?
Which method of a Form Request returns the validation rules?
Відповідь
The rules() method in a Form Request returns an associative array where each key is a field name and each value is a string or array of validation rules. This allows centralizing all validation logic outside the controller, making the code more testable and maintainable. Using Form Requests is considered a Laravel best practice for complex forms with multiple fields.
2Which Blade directive is used to protect a form against CSRF attacks?
Which Blade directive is used to protect a form against CSRF attacks?
Відповідь
The @csrf directive automatically generates a hidden field containing a security token that will be verified when the form is submitted. Laravel automatically checks this token for all POST, PUT, PATCH and DELETE requests via the VerifyCsrfToken middleware. Without this directive, requests will be rejected with a 419 error. This protection is essential to prevent Cross-Site Request Forgery attacks.
3Which validation rule should be used to verify that a field is a valid email address?
Which validation rule should be used to verify that a field is a valid email address?
Відповідь
The email rule validates that the field value matches the standard email address format. Laravel uses PHP's filter_var function with the FILTER_VALIDATE_EMAIL filter to perform this validation. This rule checks email syntax but does not guarantee that the address actually exists. For stricter validations, it is possible to combine this rule with others like unique to verify database uniqueness.
How to display old form values after a validation error?
What is the correct syntax to define multiple validation rules on a field?
+19 питань зі співбесід
Інші теми співбесід Laravel
PHP Basics
PHP OOP Essentials
Composer & Autoloading
Laravel Fundamentals
Laravel Routing
Blade Templates
Request & Response
Eloquent ORM Basics
Eloquent Relationships
Migrations & Schema Builder
Authentication
Authorization & Policies
API Resources & Authentication
Middleware
Service Container & DI
Queues & Jobs
Events & Listeners
Notifications & Mail
File Storage
Testing & PHPUnit
Caching
Livewire & Inertia
Eloquent Advanced
Repository Pattern
Laravel Packages
Performance Optimization
Security Best Practices
Laravel Octane
Laravel Distributed Systems
Observability & Monitoring
Deployment & DevOps
Опануй Laravel для наступної співбесіди
Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.
Почни безкоштовно