0
0
Laravelframework~30 mins

Filesystem configuration in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Filesystem Configuration in Laravel
📖 Scenario: You are building a Laravel application that needs to store user-uploaded files. To manage these files properly, you need to configure the filesystem settings.
🎯 Goal: Configure Laravel's filesystem to use the local disk for storing files and set up a public disk for serving files to users.
📋 What You'll Learn
Create a filesystem configuration array named disks with a local disk using the local driver and path storage_path('app').
Add a public disk configuration with the local driver, path storage_path('app/public'), url env('APP_URL').'/storage', and visibility set to public.
Set the default filesystem disk to local using a variable default.
Add the cloud disk configuration set to s3 driver using environment variables for credentials.
💡 Why This Matters
🌍 Real World
Laravel applications often need to store and serve files securely and efficiently. Configuring the filesystem allows developers to manage local and cloud storage seamlessly.
💼 Career
Understanding filesystem configuration is essential for backend Laravel developers to handle file uploads, storage, and retrieval in real-world projects.
Progress0 / 4 steps
1
Create the disks array with the local disk
Create a PHP array called disks with a key local that contains an array with driver set to 'local' and root set to storage_path('app').
Laravel
Need a hint?

Use a PHP array with keys 'disks' and inside it 'local' with 'driver' and 'root' keys.

2
Add the public disk configuration
Add a public disk inside the disks array with driver set to 'local', root set to storage_path('app/public'), url set to env('APP_URL').'/storage', and visibility set to 'public'.
Laravel
Need a hint?

Remember to add the 'public' disk inside the 'disks' array with the specified keys and values.

3
Set the default filesystem disk to local
Add a default key to the returned array and set its value to 'local'.
Laravel
Need a hint?

Add the 'default' key at the top level of the returned array and assign it 'local'.

4
Add the cloud disk configuration for S3
Add a cloud key to the returned array and set its value to 's3'. Then add an s3 disk inside the disks array with driver set to 's3', key, secret, region, and bucket set to their respective env variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION, and AWS_BUCKET.
Laravel
Need a hint?

Set the 'cloud' key to 's3' and add the 's3' disk with the required environment variables inside 'disks'.