0
0
Laravelframework~10 mins

File uploads in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to validate a file upload in a Laravel controller.

Laravel
request()->validate(['photo' => '[1]']);
Drag options to blanks, or click blank then click option'
A'required|email'
B'nullable|integer'
C'string|max:255'
D'required|file|image'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'email' rules for file uploads.
Not including 'file' in the validation rules.
2fill in blank
medium

Complete the code to store an uploaded file in Laravel's storage.

Laravel
$path = $request->file('photo')->[1]('photos');
Drag options to blanks, or click blank then click option'
Astore
Bsave
Cupload
Dmove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'move' which is a PHP method but not recommended in Laravel.
Using 'upload' which does not exist.
3fill in blank
hard

Fix the error in the code to get the original filename of the uploaded file.

Laravel
$filename = $request->file('photo')->[1]();
Drag options to blanks, or click blank then click option'
AgetClientOriginalName
BgetOriginalName
CoriginalName
DgetClientName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getOriginalName' which does not exist.
Using 'originalName' property which is invalid.
4fill in blank
hard

Fill both blanks to check if a file was uploaded and then store it.

Laravel
if ($request->hasFile('[1]') && $request->file('[2]')->isValid()) {
    $path = $request->file('photo')->store('uploads');
}
Drag options to blanks, or click blank then click option'
Aphoto
Bfile
Cimage
Dupload
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in 'hasFile' and 'file' methods.
Using generic names like 'file' or 'upload' instead of the actual input name.
5fill in blank
hard

Fill all three blanks to create a unique filename and store the uploaded file.

Laravel
$filename = time() . '_' . $request->file('[1]')->getClientOriginalName();
$path = $request->file('[2]')->storeAs('[3]', $filename);
Drag options to blanks, or click blank then click option'
Aphoto
Bimage
Cuploads
Dfiles
Attempts:
3 left
💡 Hint
Common Mistakes
Using different input names in the two file calls.
Using wrong folder names for storage.