0
0
Laravelframework~30 mins

Public disk and symbolic links in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Public disk and symbolic links in Laravel
📖 Scenario: You are building a Laravel application that needs to store user-uploaded images in a public directory. To make these images accessible via the web, you need to set up the public disk and create a symbolic link from the storage folder to the public folder.
🎯 Goal: Set up the public disk configuration in Laravel and create a symbolic link so that files stored in storage/app/public are accessible from the public/storage URL.
📋 What You'll Learn
Create the public disk configuration in config/filesystems.php with the correct root and URL
Create a symbolic link from public/storage to storage/app/public using the Artisan command
Verify that the symbolic link exists and points to the correct folder
Explain how to store a file using the public disk
💡 Why This Matters
🌍 Real World
Many web applications need to store user-uploaded files like images or documents and make them accessible via URLs. Setting up the public disk and symbolic links in Laravel is a common way to achieve this.
💼 Career
Understanding Laravel's filesystem and storage linking is essential for backend developers working with file uploads, media management, and serving static assets securely.
Progress0 / 4 steps
1
Configure the public disk in filesystems.php
Open the config/filesystems.php file and add the public disk configuration array inside the disks array exactly as follows: 'public' => ['driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public'].
Laravel
Need a hint?

Look for the disks array and add the public disk with the exact keys and values.

2
Create the symbolic link with Artisan
Run the Artisan command php artisan storage:link in your terminal to create a symbolic link from public/storage to storage/app/public.
Laravel
Need a hint?

Use the Laravel Artisan command storage:link to create the symbolic link.

3
Verify the symbolic link exists
Check that the public/storage folder is a symbolic link pointing to storage/app/public. You can verify this by running ls -l public in your terminal and looking for the storage -> ../storage/app/public link.
Laravel
Need a hint?

Use the ls -l public command to see if the symbolic link storage exists and points correctly.

4
Store a file using the public disk
Write a Laravel code snippet that stores an uploaded file called $request->file('photo') in the public disk using store('photos', 'public') method and saves the returned path in a variable called $path.
Laravel
Need a hint?

Use the store method on the uploaded file with the folder 'photos' and disk 'public'.