Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to delete a file using Laravel's Storage facade.
Laravel
use Illuminate\Support\Facades\Storage; Storage::[1]('path/to/file.txt');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using PHP's unlink function directly instead of Storage facade.
Using a method name that does not exist in Storage facade.
✗ Incorrect
Laravel's Storage facade uses the delete method to remove files.
2fill in blank
mediumComplete the code to check if a file exists before deleting it.
Laravel
if (Storage::[1]('path/to/file.txt')) { Storage::delete('path/to/file.txt'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
has which is not a method in Storage facade.Using
contains which is for collections, not files.✗ Incorrect
The exists method checks if a file is present in storage.
3fill in blank
hardFix the error in the code to delete a file from a specific disk.
Laravel
Storage::disk('[1]')->delete('file.txt');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a disk name that is not configured in Laravel.
Using 'storage' which is not a disk name.
✗ Incorrect
The public disk is commonly used for publicly accessible files in Laravel.
4fill in blank
hardFill both blanks to delete multiple files using Laravel's Storage facade.
Laravel
Storage::[1](['file1.txt', '[2]']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' instead of 'delete' method.
Passing a variable instead of a string file name.
✗ Incorrect
The delete method can accept an array of file paths to delete multiple files at once.
5fill in blank
hardFill all three blanks to delete a file and check the result in Laravel.
Laravel
$deleted = Storage::[1]('path/to/file.txt'); if ($deleted) { echo '[2]'; } else { echo '[3]'; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' instead of 'delete'.
Mixing up success and failure messages.
✗ Incorrect
The delete method returns true if the file was deleted successfully. We print a success or failure message accordingly.