Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
What is the primary purpose of the CSRF token in Laravel forms?
Not quite. Try another option.
Answer: To protect the application from Cross-Site Request Forgery attacks
Laravel generates a CSRF 'token' for each active user session managed by the application. This token is used to verify that the authenticated user is the one actually making the requests to the application, preventing Cross-Site Request Forgery.
Question 2 of 50
Which Blade directive is used to generate the hidden CSRF token input field inside a form?
Not quite. Try another option.
Answer: @csrf
The @csrf Blade directive generates the hidden HTML input field containing the CSRF token, like so: <input type="hidden" name="_token" value="...">.
Question 3 of 50
If a POST request is made to a Laravel route without a valid CSRF token, which HTTP status code is typically returned?
Not quite. Try another option.
Answer: 419 Page Expired
By default, if the VerifyCsrfToken middleware detects a missing or mismatching token, Laravel aborts the request with a 419 Page Expired status.
Question 4 of 50
HTML forms natively support which of the following HTTP verbs?
Not quite. Try another option.
Answer: GET and POST only
HTML forms currently only support GET and POST methods. To use PUT, PATCH, or DELETE, method spoofing is required.
Question 5 of 50
Which Blade directive helps in performing 'Method Spoofing' to simulate PUT or DELETE requests?
Not quite. Try another option.
Answer: @method
The @method directive creates a hidden input field named _method containing the spoofed HTTP verb (e.g., @method('PUT')). Laravel detects this and routes the request accordingly.
Question 6 of 50
What is the name of the hidden input field used by Laravel to determine the spoofed HTTP method?
Not quite. Try another option.
Answer: _method
Laravel looks for a request parameter named _method (e.g., <input type="hidden" name="_method" value="PUT">) to determine the intended HTTP verb.
Question 7 of 50
In a controller, which method is most commonly called on the $request object to validate incoming data?
Not quite. Try another option.
Answer: $request->validate()
The validate method is the standard way to validate incoming request data in a controller. If validation fails, it handles the redirect automatically.
Question 8 of 50
What happens automatically when the $request->validate() method fails?
Not quite. Try another option.
Answer: It redirects the user back to the previous location with errors and input flashed to the session
Laravel's base controller validation logic automatically redirects the user back to the previous location (usually the form) with the validation errors and the old input data flashed to the session.
Question 9 of 50
Which validation rule ensures that a field must be present in the input data and not empty?
Not quite. Try another option.
Answer: required
The required rule ensures the field is present in the input data and is not empty (null, empty string, or empty array).
Question 10 of 50
How can you specify multiple validation rules for a single field using the pipe syntax?
Laravel allows separating multiple string-based rules using the pipe character |.
Question 11 of 50
Which data structure can be used as an alternative to the pipe syntax for defining rules?
Not quite. Try another option.
Answer: PHP Array
Rules can be defined using an array, which is often preferred for rules that take arguments to avoid parsing issues. Example: ['required', 'unique:posts', 'max:255'].
Question 12 of 50
Which validation rule checks if two fields (e.g., password and password_confirmation) have the same value?
Not quite. Try another option.
Answer: confirmed
The confirmed rule expects a matching field with _confirmation appended to the name (e.g., checking password requires password_confirmation).
Question 13 of 50
What does the unique:users validation rule check?
Not quite. Try another option.
Answer: That the input value does not already exist in the users database table
The unique:table_name rule verifies that the data provided does not already exist in the specified database table.
Question 14 of 50
If you want a field to be optional but validated if it is present, which rule should typically accompany specific constraints?
Not quite. Try another option.
Answer: nullable
The nullable rule allows the field to be null. Without it, validation rules like string or email might fail if the value is null/empty.
Question 15 of 50
Which variable is automatically shared with all views to display validation errors?
Not quite. Try another option.
Answer: $errors
The $errors variable (an instance of Illuminate\Support\MessageBag) is shared with all views by the ShareErrorsFromSession middleware.
Question 16 of 50
How do you check if there are any validation errors in a Blade view?
Not quite. Try another option.
Answer: @if($errors->any())
The any() method on the $errors object returns true if there are any error messages present.
Question 17 of 50
Which method retrieves the first error message for a specific field?
Not quite. Try another option.
Answer: $errors->first('field_name')
The first('field_name') method returns the first error message for the given field, or an empty string if none exist.
Question 18 of 50
Which Blade directive allows you to quickly check for validation errors on a specific field and display them?
Not quite. Try another option.
Answer: @error('email')
The @error('field') directive checks if an error exists for that field. Inside the directive, the $message variable contains the error message.
Answer: The validation error message for the 'title' field
Inside the @error directive block, Laravel injects a $message variable containing the error text for the specified field.
Question 20 of 50
To repopulate a form field with its previous value after a validation failure, which helper function is used?
Not quite. Try another option.
Answer: old()
The old('field_name') helper retrieves the value of a field that was flashed to the session during the previous request.
Question 21 of 50
What is the second argument of the old() helper function used for? e.g. old('email', $user->email)
Not quite. Try another option.
Answer: It sets a default value if the old input is not found
The second argument is the default value, which is useful for edit forms where you want to show the database value initially, but show the user's failed input if validation fails on update.
Question 22 of 50
Which Artisan command creates a new custom validation rule class?
Not quite. Try another option.
Answer: php artisan make:rule RuleName
The make:rule command generates a new rule class in the app/Rules directory.
Question 23 of 50
In a custom Rule class implementing Illuminate\Contracts\Validation\Rule, which method contains the validation logic?
Not quite. Try another option.
Answer: passes()
The passes($attribute, $value) method returns true or false indicating whether the validation passed.
Question 24 of 50
In a custom Rule class, what is the purpose of the message() method?
Not quite. Try another option.
Answer: To return the validation error message if validation fails
The message() method returns the string that should be displayed to the user if the passes() method returns false.
Question 25 of 50
Which validation rule stops the validation process for a field immediately after the first failure?
Not quite. Try another option.
Answer: bail
The bail rule stops running validation rules on the attribute after the first validation failure.
Question 26 of 50
How would you validate that an uploaded file is an image?
Not quite. Try another option.
Answer: 'photo' => 'image'
The image rule validates that the file is an image (jpeg, png, bmp, gif, svg, or webp).
Question 27 of 50
What is the correct syntax to define a custom error message for a specific rule on a specific attribute in the validate method?
Not quite. Try another option.
Answer: Pass an array as the third argument: ['email.required' => 'We need your email!']
The validate method accepts rules as the first argument and custom messages as the second (or third, depending on method signature context, but in Request::validate(rules, messages) it is the second). Wait, strictly speaking validate(rules, messages, attributes). So it is the second argument.
Question 28 of 50
Correction on previous logic: In $request->validate($rules, $messages), the messages array is passed as which argument?
Not quite. Try another option.
Answer: Second
The signature is validate(array $rules, array $messages = [], array $customAttributes = []). Custom messages are the second argument.
Question 29 of 50
Which rule checks that a value is within a given list of values?
Not quite. Try another option.
Answer: in
The in:foo,bar,... rule ensures the field value is contained within the given list of values.
Question 30 of 50
What does the max:255 rule implies when validating a numeric field?
Not quite. Try another option.
Answer: The number must be less than or equal to 255
Validation rules in Laravel are polymorphic. For numeric fields, max corresponds to the numeric value. For strings, it corresponds to character length.
Question 31 of 50
What does max:1024 imply when validating a file upload?
Not quite. Try another option.
Answer: Max 1024 kilobytes
For files, size rules (min, max, between, size) correspond to the file size in kilobytes.
Question 32 of 50
How can you validate nested array input, for example, checking the name of every person in a people array?
Not quite. Try another option.
Answer: 'people.*.name' => 'required'
Laravel uses dot notation and the asterisk * wildcard to validate nested array attributes.
Question 33 of 50
Which rule ensures a string is a valid URL?
Not quite. Try another option.
Answer: url
The url rule validates that the field is a valid URL string.
Question 34 of 50
Which of the following is NOT a valid way to specify a custom validation rule?
Not quite. Try another option.
Answer: Using a standard PHP if statement inside the rules array
The rules array expects strings or objects/closures. You cannot put control structures like if statements inside the array definition itself (though you can build the array conditionally before passing it).
Question 35 of 50
When using a Closure for custom validation, how do you signal a failure?
Not quite. Try another option.
Answer: Call the $fail callback with the error message
Modern Laravel validation closures accept a $fail argument. You call $fail('Error message') to invalidate the attribute.
Question 36 of 50
What is the purpose of the FormRequest class in Laravel?
Not quite. Try another option.
Answer: To encapsulate validation and authorization logic in a dedicated class
Form Requests allow you to move complex validation and authorization logic out of controllers, keeping them slim.
Question 37 of 50
In a FormRequest class, what does the authorize() method do?
Not quite. Try another option.
Answer: It checks if the user has permission to make the request
The authorize method returns a boolean determining if the authenticated user is allowed to perform the request.
Question 38 of 50
Which rule validates that the field under validation matches a given regular expression?
Not quite. Try another option.
Answer: regex
The regex:pattern rule validates the input against the provided regular expression.
Question 39 of 50
To use the regex rule inside a pipe-delimited string, what must you be careful about?
Not quite. Try another option.
Answer: You must use an array instead of a pipe string to avoid conflict
Because the pipe | is the delimiter, if your regex contains a pipe, it breaks the parsing. It is recommended to use the array syntax for rules using regex.
Question 40 of 50
If you want to validate a date and ensure it is after a specific date (e.g., tomorrow), which rule would you use?
Not quite. Try another option.
Answer: after:tomorrow
The after:date rule validates that the field is a value after the given date. tomorrow is a valid date string understood by PHP's strtotime.
Question 41 of 50
Which method is used to retrieve validated data from a FormRequest instance?
Not quite. Try another option.
Answer: $request->validated()
The validated() method returns an array of the data that was validated and passed the rules.
Question 42 of 50
Why might you get a TokenMismatchException?
Not quite. Try another option.
Answer: The CSRF token is missing or invalid
This exception is thrown by the VerifyCsrfToken middleware when the submitted token does not match the session token.
Question 43 of 50
How can you exclude specific URIs from CSRF protection?
Not quite. Try another option.
Answer: Add URIs to the $except array in the VerifyCsrfToken middleware
The VerifyCsrfToken middleware class contains an $except property where you can list URIs that should not require CSRF verification (e.g., webhooks).
Question 44 of 50
The accepted validation rule is commonly used for:
Not quite. Try another option.
Answer: Terms of Service acceptance (checkbox)
The accepted rule validates that the field is yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.
Question 45 of 50
What is the key difference between size rule and min/max rules?
Not quite. Try another option.
Answer: size validates an exact amount (characters, number, or file size), whereas min/max validate a range
The size:value rule requires the field to have a size matching the given value exactly.
Question 46 of 50
Which rule validates that the value must exist in a given database table?
Not quite. Try another option.
Answer: exists
The exists:table,column rule validates that the value exists in the specified database table.
Question 47 of 50
When repopulating forms, what does <input type="text" name="email" value="{{ old('email') }}"> ensure?
Not quite. Try another option.
Answer: The input retains the user's entry after a validation error redirect
The old helper retrieves the input data from the previous request (flashed to session), preventing the user from having to re-type valid or invalid data.
Question 48 of 50
If you need to validate a boolean value, which rule should be used?
Not quite. Try another option.
Answer: boolean
The boolean rule validates that the field is able to be cast as a boolean. Accepted input includes true, false, 1, 0, "1", and "0".
Question 49 of 50
In a Blade template, how is the $errors variable passed to the view?
Not quite. Try another option.
Answer: It is injected via the ShareErrorsFromSession middleware
The Illuminate\View\Middleware\ShareErrorsFromSession middleware ensures that an $errors variable is available in all views.
Question 50 of 50
Which validation rule is the opposite of accepted?
Not quite. Try another option.
Answer: declined
The declined rule validates that the field is no, off, 0, or false.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of INT221 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of INT221 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.