Recall & Review
beginner
What is the basic Laravel method to handle file uploads in a controller?
Use the
store() method on the uploaded file instance, like $request->file('photo')->store('folder') to save the file in storage.Click to reveal answer
beginner
How do you validate an uploaded file in Laravel?
Use the
validate() method on the request with rules like 'file' => 'required|file|mimes:jpg,png|max:2048' to check presence, type, and size.Click to reveal answer
intermediate
What is the purpose of the
public_path() helper in file uploads?It returns the path to the public folder, useful when you want to move or save uploaded files where they can be accessed by the browser.
Click to reveal answer
intermediate
How can you generate a unique filename for an uploaded file in Laravel?
Use
Str::uuid() or time() combined with the original extension, for example: $filename = time() . '.' . $file->getClientOriginalExtension();Click to reveal answer
intermediate
What is the difference between
store() and storeAs() methods in Laravel file uploads?store() saves the file with a generated unique name, while storeAs() lets you specify the exact filename to save.Click to reveal answer
Which Laravel method is used to retrieve an uploaded file from a request?
✗ Incorrect
The correct method to get an uploaded file is
$request->file('input_name').How do you validate that an uploaded file is an image and less than 2MB in Laravel?
✗ Incorrect
Use
file and image rules together with max:2048 to validate image files under 2MB.What does the
store('folder') method do with an uploaded file?✗ Incorrect
store('folder') saves the file in storage/app/folder with a unique generated filename.Which helper function returns the path to the public directory in Laravel?
✗ Incorrect
public_path() returns the full path to the public folder where web-accessible files are stored.If you want to save an uploaded file with a custom name, which method should you use?
✗ Incorrect
storeAs() lets you specify the folder and filename to save the uploaded file.Explain the steps to upload and save a file in Laravel, including validation and storage.
Think about how you handle the file from the form to storage.
You got /5 concepts.
Describe how Laravel helps ensure uploaded files are safe and valid before saving.
Focus on validation and storage safety.
You got /4 concepts.