Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Eloquent ORM, Security & Queue Ecosystem (11 - 24)

34%
Laravel & Ecosystem (50 Qs)•Part 2: Eloquent ORM, Security & Queue Ecosystem (11 - 24)

What are Form Requests and Custom Validation Rules?

junior LevelCode ExampleFormsSecurity & AuthData Structures

In Simple Words: Custom request classes that encapsulate authorization and validation logic outside of controllers:

  • Validates incoming parameters before the controller method is ever executed:
php
class StoreUserRequest extends FormRequest {
    public function authorize(): bool {
        return $this->user()->can('create', User::class);
    }
    public function rules(): array {
        return [
            'email' => 'required|email|unique:users,email',
            'password' => ['required', 'confirmed', Password::min(8)->letters()->numbers()]
        ];
    }
}
  • If validation fails, it automatically redirects back with error messages or returns a 422 JSON response.