Skip to main content
InterviewHubPRO
Section Overview
Q40

Question 40 of 50

Part 3: Octane, High-Throughput Scaling & Enterprise Design (25 - 35)

80%
Laravel & Ecosystem (50 Qs)•Part 3: Octane, High-Throughput Scaling & Enterprise Design (25 - 35)

Form Requests & Authorization Callbacks.

senior LevelCode ExampleFormsSecurity & Auth

In Simple Words: Form Requests encapsulate validation and authorization logic away from controllers:

  • authorize(): Checks if the authenticated user has permission to perform the action using Gates or Policies.
  • rules(): Returns an array of validation rules.
  • after() hook (Laravel 10+): Adds custom cross-field validation closures to run after standard rules pass.
php
public function after(): array {
    return [
        function (Validator $validator) {
            if ($this->somethingElseIsInvalid()) {
                $validator->errors()->add('field', 'Custom cross-validation failure.');
            }
        }
    ];
}