0
0
Laravelframework~10 mins

Uploading files 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 get the uploaded file from the request.

Laravel
$file = $request->[1]('photo');
Drag options to blanks, or click blank then click option'
AgetFile
Bfile
Cupload
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using $request->input() instead of $request->file()
Trying to use $request->upload() which does not exist
2fill in blank
medium

Complete the code to store the uploaded file in the 'uploads' directory.

Laravel
$path = $file->[1]('uploads');
Drag options to blanks, or click blank then click option'
Asave
Bupload
Cmove
Dstore
Attempts:
3 left
💡 Hint
Common Mistakes
Using save which is not a method on the uploaded file object
Using move without specifying full path
3fill in blank
hard

Fix the error in the code to check if the request has a file named 'avatar'.

Laravel
if ($request->[1]('avatar')) {
    // process file
}
Drag options to blanks, or click blank then click option'
AhasFile
BfileExists
Chas
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using has which checks input but not files
Using exists which is not a request method
4fill in blank
hard

Fill both blanks to validate that the uploaded file is required and must be an image.

Laravel
$request->validate([
    'photo' => '[1]|[2]'
]);
Drag options to blanks, or click blank then click option'
Arequired
Bimage
Cfile
Dnullable
Attempts:
3 left
💡 Hint
Common Mistakes
Using file instead of image to check file type
Using nullable which allows no file
5fill in blank
hard

Fill all three blanks to rename the uploaded file and move it to 'public/images'.

Laravel
$file = $request->file('photo');
$filename = time() . '.' . $file->[1]();
$file->[2](public_path('[3]'), $filename);
Drag options to blanks, or click blank then click option'
AgetClientOriginalExtension
Bmove
Cimages
Dstore
Attempts:
3 left
💡 Hint
Common Mistakes
Using store instead of move for moving to public folder
Forgetting to add the file extension when renaming
Using wrong folder name or path