Bird
Raised Fist0
Laravelframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of the public disk in Laravel's filesystem?
easy
A. To store files that should be accessible publicly via the web
B. To store configuration files for the application
C. To keep temporary cache files hidden from users
D. To store database backups securely

Solution

  1. Step 1: Understand the role of the public disk

    The public disk is designed to hold files that need to be accessed by users through the web, such as images or documents.
  2. Step 2: Compare with other storage uses

    Other disks like local or private are for internal use, not for public access.
  3. Final Answer:

    To store files that should be accessible publicly via the web -> Option A
  4. Quick Check:

    Public disk = public files [OK]
Hint: Public disk means web-accessible files [OK]
Common Mistakes:
  • Confusing public disk with private storage
  • Thinking public disk stores config or cache files
  • Assuming public disk is for backups
2. Which Artisan command creates a symbolic link from public/storage to storage/app/public?
easy
A. php artisan storage:create-link
B. php artisan make:link
C. php artisan link:storage
D. php artisan storage:link

Solution

  1. Step 1: Recall the correct Artisan command

    Laravel uses php artisan storage:link to create the symbolic link for public storage access.
  2. Step 2: Verify other options

    Other commands listed are not valid Laravel Artisan commands for this purpose.
  3. Final Answer:

    php artisan storage:link -> Option D
  4. Quick Check:

    Storage link command = storage:link [OK]
Hint: Use 'storage:link' to create public storage link [OK]
Common Mistakes:
  • Using incorrect Artisan command names
  • Confusing 'make' or 'create' with 'storage:link'
  • Trying to create symbolic links manually without Artisan
3. Given the following code snippet, what will Storage::disk('public')->url('file.txt') return if the symbolic link is correctly created?
use Illuminate\Support\Facades\Storage;

$url = Storage::disk('public')->url('file.txt');
echo $url;
medium
A. storage/app/file.txt
B. http://your-app-url/storage/file.txt
C. /public/storage/file.txt
D. /storage/app/public/file.txt

Solution

  1. Step 1: Understand Storage::url() behavior on public disk

    When the symbolic link is created, Storage::url() returns a URL starting with '/storage/' pointing to the public folder.
  2. Step 2: Confirm the full URL format

    The method returns a full URL including the app's base URL, so it looks like 'http://your-app-url/storage/file.txt'.
  3. Final Answer:

    http://your-app-url/storage/file.txt -> Option B
  4. Quick Check:

    Storage::url() returns public URL [OK]
Hint: Storage::url() returns full public URL [OK]
Common Mistakes:
  • Expecting a file system path instead of URL
  • Confusing storage path with public URL
  • Missing the base URL in the returned string
4. You ran php artisan storage:link but your files in storage/app/public are not accessible via the browser. What is the most likely cause?
medium
A. You forgot to clear the application cache
B. The files are not readable by the web server
C. The symbolic link was not created or points to the wrong folder
D. The public disk is not configured in config/filesystems.php

Solution

  1. Step 1: Check the symbolic link existence and target

    If the symbolic link is missing or points incorrectly, files won't be accessible via public/storage.
  2. Step 2: Consider other causes but focus on link

    While file permissions matter, the most common cause after running the command is a failed or incorrect link creation.
  3. Final Answer:

    The symbolic link was not created or points to the wrong folder -> Option C
  4. Quick Check:

    Broken or missing link = no public access [OK]
Hint: Check symbolic link path if files not accessible [OK]
Common Mistakes:
  • Assuming cache clearing fixes symbolic link issues
  • Ignoring file permissions as a cause
  • Not verifying the link target folder
5. You want to serve user-uploaded images stored in storage/app/public/images via the web. Which steps correctly set this up in Laravel?
hard
A. Run php artisan storage:link and access images via /storage/images/filename.jpg
B. Move images to public/images and access directly without symbolic links
C. Configure a new disk in config/filesystems.php pointing to public/images and use Storage::url()
D. Create a route to read files from storage/app/public/images and return them manually

Solution

  1. Step 1: Create symbolic link for public storage

    Running php artisan storage:link creates a link from public/storage to storage/app/public, making files accessible.
  2. Step 2: Access images via the public URL path

    Files inside storage/app/public/images are then accessible at /storage/images/filename.jpg.
  3. Final Answer:

    Run php artisan storage:link and access images via /storage/images/filename.jpg -> Option A
  4. Quick Check:

    Symbolic link + /storage/ URL = public access [OK]
Hint: Use storage:link and /storage/ URL for public files [OK]
Common Mistakes:
  • Moving files manually instead of linking
  • Not using the symbolic link and expecting direct access
  • Overcomplicating with custom routes unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard