0
0
Laravelframework~20 mins

Public disk and symbolic links in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Public Disk & Symbolic Link Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you access a file stored on the public disk without creating a symbolic link?

In Laravel, the public disk stores files in storage/app/public. To make these files accessible via the web, a symbolic link is usually created from public/storage to storage/app/public.

What will happen if you try to access a file stored on the public disk via a URL without creating this symbolic link?

AThe web server will return a 404 Not Found error because the file is not reachable.
BThe file will be accessible via the URL as expected.
CLaravel will automatically create the symbolic link on the first request.
DThe file will be downloaded instead of displayed in the browser.
Attempts:
2 left
💡 Hint

Think about how the web server serves files from the public directory and what happens if the symbolic link is missing.

📝 Syntax
intermediate
1:30remaining
Which Artisan command correctly creates the symbolic link for the public disk?

Laravel provides an Artisan command to create the symbolic link from public/storage to storage/app/public. Which of the following commands is correct?

Aphp artisan storage:create-link
Bphp artisan make:link
Cphp artisan link:storage
Dphp artisan storage:link
Attempts:
2 left
💡 Hint

Check the official Laravel documentation for the exact command name.

🔧 Debug
advanced
2:30remaining
Why does this Laravel code fail to access a public disk file after deployment?

After deploying a Laravel app, the following code tries to get the URL of a file stored on the public disk:

Storage::disk('public')->url('example.jpg');

But the URL returns a 404 error. What is the most likely cause?

AThe file <code>example.jpg</code> does not exist in <code>storage/app/public</code>.
BThe symbolic link from <code>public/storage</code> to <code>storage/app/public</code> was not created on the server.
CThe <code>public</code> disk is not configured in <code>config/filesystems.php</code>.
DThe web server does not have permission to read the <code>storage/app/public</code> directory.
Attempts:
2 left
💡 Hint

Consider what is required for the web server to serve files stored on the public disk.

🧠 Conceptual
advanced
2:00remaining
What is the purpose of the symbolic link in Laravel's public disk setup?

Laravel uses a symbolic link from public/storage to storage/app/public. Why is this symbolic link necessary?

ATo allow files stored in <code>storage/app/public</code> to be accessible via the web through the <code>public</code> directory.
BTo move files from <code>storage/app/public</code> to <code>public/storage</code> automatically.
CTo prevent users from accessing files in <code>storage/app/public</code> directly.
DTo back up files stored in <code>storage/app/public</code> to the <code>public</code> directory.
Attempts:
2 left
💡 Hint

Think about how web servers serve files and where Laravel stores user-uploaded files.

state_output
expert
2:00remaining
What is the output of this Laravel code snippet regarding symbolic link existence?

Consider this Laravel code snippet executed in a controller method:

if (is_link(public_path('storage'))) {
    echo 'Link exists';
} else {
    echo 'Link missing';
}

Assuming the symbolic link was created correctly, what will be the output?

Laravel
if (is_link(public_path('storage'))) {
    echo 'Link exists';
} else {
    echo 'Link missing';
}
ARuntime error because public_path() is undefined
BLink missing
CLink exists
DSyntax error due to missing semicolon
Attempts:
2 left
💡 Hint

Recall what is_link() checks and what public_path() returns in Laravel.