skip to content

Request Data & Replies

The Request and Response objects a Laravel handler uses: input, uploads, the session, views, JSON, redirects, streams and API resources. Interviewers use them to check everyday handler fluency.

on this pageshow

explore

questions

page 2 of 2

In a Laravel quote wizard, two concurrent requests on one session each save a step and one change disappears; why, and how does ->block() help?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Laravel loads the session when a request starts and writes the whole payload back at the end, unlocked, so the later of two overlapping requests overwrites the other's change. ->block() on the routes serialises them with a per-session cache lock.

open as a page

In a Laravel streamed response, why do session writes inside the stream callback get lost, and what happens to an exception thrown there?

level: seniorimportance: should knowfreq 22%

basics

~20 s

A streamed response's callback runs during send(), after the HTTP kernel and all middleware, including StartSession's save, have finished. Session changes made there are never persisted, and an exception cannot change the already-sent 200 status.

open as a page

For a Laravel sales report of a million rows, when do you stream it in the request, and when do you generate it in a queued job instead?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Stream with streamDownload() when the export finishes within about a minute and the user waits for it. Queue a job that writes the file to a disk and sends a link when it runs longer, must survive failures, or many users export at once.

open as a page

A Laravel dating app rejects large profile photos, sometimes with a 413 PostTooLargeException and sometimes with 'The photo failed to upload.'; why two symptoms?

level: seniorimportance: should knowfreq 45%

basics

~20 s

A body over post_max_size is stopped by the global ValidatePostSize middleware with a 413 PostTooLargeException. A file over upload_max_filesize but inside post_max_size reaches the controller as an invalid UploadedFile, and validation reports it as failed to upload.

open as a page

In Laravel, how do Response::macro() and a class implementing Responsable each let you reuse one response shape across controllers?

level: middleimportance: nice to knowfreq 16%

basics

~10 s

Response::macro('name', fn) adds a method to the response factory, so response()->name(...) builds the shared shape anywhere. A Responsable class implements toResponse($request), and the router calls it when a controller returns that object.

open as a page

Laravel 13's session config sets serialization to json; what does that change about stored values, and what happens when an upgraded app switches?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

With 'serialization' => 'json', the session payload is json_encode'd, so objects such as models or value objects come back as plain arrays. It removes PHP unserialize() from the session path; switching an existing app from php invalidates every active session.

open as a page

showing 31–37 of 37