0
0
Laravelframework~20 mins

Local disk storage in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Local Disk Storage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Laravel code output when storing a file locally?
Consider this Laravel code snippet that stores an uploaded file locally. What will be the output of echo $path; if the file is successfully stored?
Laravel
<?php
use Illuminate\Http\Request;

Route::post('/upload', function (Request $request) {
    $path = $request->file('photo')->store('images');
    echo $path;
});
AAn error because the 'images' directory does not exist
Bimages/filename.ext (where filename.ext is the original file name)
C/storage/images/filename.ext (full URL path to the file)
Dimages/randomstring.ext (a random generated file name with original extension)
Attempts:
2 left
💡 Hint
Think about how Laravel generates file names when storing files with the store() method.
📝 Syntax
intermediate
2:00remaining
Which option correctly configures the local disk in Laravel's filesystems.php?
You want to configure the local disk to store files in the storage/app/public directory and make them publicly accessible. Which configuration snippet is correct?
A'local' => [ 'driver' => 'local', 'root' => public_path('storage'), 'url' => env('APP_URL').'/storage', 'visibility' => 'private', ]
B'local' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/public', 'visibility' => 'public', ]
C'local' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ]
D'local' => [ 'driver' => 'local', 'root' => storage_path('app'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ]
Attempts:
2 left
💡 Hint
Check the root path and visibility settings for public access.
🔧 Debug
advanced
2:00remaining
Why does this Laravel code fail to retrieve a file from local storage?
Given this code snippet, why does Storage::disk('local')->get('file.txt') throw an exception?
Laravel
<?php
use Illuminate\Support\Facades\Storage;

$content = Storage::disk('local')->get('file.txt');
AThe file 'file.txt' does not exist in storage/app directory
BThe 'local' disk is not defined in config/filesystems.php
CThe get() method requires a full URL, not a relative path
DThe Storage facade is not imported correctly
Attempts:
2 left
💡 Hint
Check if the file path is correct and the file exists in the expected directory.
state_output
advanced
2:00remaining
What is the output of this Laravel code that deletes a file from local storage?
What will be the value of $deleted after running this code if the file exists?
Laravel
<?php
use Illuminate\Support\Facades\Storage;

$deleted = Storage::disk('local')->delete('oldfile.txt');
echo $deleted ? 'Deleted' : 'Not deleted';
AThrows an exception because delete() returns void
BDeleted
CNot deleted
DThrows an exception because the file path is incorrect
Attempts:
2 left
💡 Hint
Check what the delete() method returns when the file exists.
🧠 Conceptual
expert
3:00remaining
Which statement about Laravel's local disk storage is TRUE?
Select the correct statement about how Laravel handles local disk storage.
AThe local disk stores files in the <code>storage/app</code> directory and requires a symbolic link to <code>public/storage</code> for public access
BFiles stored using the local disk are accessible publicly by default without extra configuration
CLaravel automatically creates the <code>storage/app/public</code> directory if it does not exist when storing files
DThe local disk driver encrypts files automatically before saving them to disk
Attempts:
2 left
💡 Hint
Think about how Laravel manages public access to files stored locally.