0
0
Laravelframework~10 mins

Deleting 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 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'
Aremove
Bdestroy
Cunlink
Ddelete
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.
2fill in blank
medium

Complete 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'
Acontains
Bhas
Cexists
Dfound
Attempts:
3 left
💡 Hint
Common Mistakes
Using has which is not a method in Storage facade.
Using contains which is for collections, not files.
3fill in blank
hard

Fix 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'
Alocal
Bpublic
Cremote
Dstorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using a disk name that is not configured in Laravel.
Using 'storage' which is not a disk name.
4fill in blank
hard

Fill 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'
Adelete
Bfile2.txt
Cfile3.txt
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' instead of 'delete' method.
Passing a variable instead of a string file name.
5fill in blank
hard

Fill 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'
Adelete
BFile deleted successfully
CFile could not be deleted
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' instead of 'delete'.
Mixing up success and failure messages.