The store() method saves the file in the specified folder with a unique generated filename to avoid overwriting.
Step 2: Analyze returned path
The returned path includes the folder and the unique filename, not the original filename or full storage path.
Final Answer:
"images/unique_generated_name.jpg" -> Option D
Quick Check:
store() returns folder + unique filename = A [OK]
Hint: store() saves file with unique name, returns folder plus new filename [OK]
Common Mistakes:
Assuming original filename is kept
Expecting full storage path returned
Confusing store() with move() method
4. Identify the error in this Laravel file upload code:
if ($request->hasFile('avatar')) {
$file = $request->file('avatar');
$file->move('uploads');
}
medium
A. Missing second argument for move() method
B. Incorrect method to check file existence
C. move() should be called on $request, not $file
D. No error, code is correct
Solution
Step 1: Review move() method signature
The move() method requires two arguments: destination path and filename.
Step 2: Check code arguments
Only one argument ('uploads') is given; filename is missing, causing an error.
Final Answer:
Missing second argument for move() method -> Option A
Quick Check:
move() needs path and filename = C [OK]
Hint: move() needs destination path and filename both [OK]
Common Mistakes:
Calling move() with only one argument
Confusing hasFile() with fileExists()
Calling move() on request instead of file
5. You want to upload multiple images and save their paths in the database. Which Laravel approach correctly handles multiple file uploads in a request named photos?
hard
A.
if ($request->hasFile('photos')) {
$path = $request->file('photos')->store('gallery');
Photo::create(['path' => $path]);
}