What is the request object in Laravel?
Why Interviewers Ask This
This is a classic screening question for Laravel roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
The Request object in Laravel (Illuminate\Http\Request) wraps the current HTTP request and provides a clean API for accessing all request data. Inject it in a controller: public function store(Request $request). Access input: $request->input("name"), $request->get("name"), $request->post("name"). Check if input exists: $request->has("name"), $request->filled("name") (exists and not empty). Get all input: $request->all(). Only specific fields: $request->only(["name", "email"]). Except fields: $request->except(["password"]). File uploads: $request->file("avatar"). Check request type: $request->isJson(), $request->expectsJson(). Get headers: $request->header("Accept").
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.