What is the purpose of the config/filesystems.php file in Laravel?
It defines how Laravel interacts with different storage systems, like local disks, cloud storage, and FTP servers. It sets up 'disks' that Laravel can use to save and retrieve files.
Click to reveal answer
beginner
What is a 'disk' in Laravel's filesystem configuration?
A 'disk' is a named storage location defined in config/filesystems.php. It can point to local folders, cloud services like Amazon S3, or other storage types.
Click to reveal answer
beginner
How do you set the default filesystem disk in Laravel?
You set the default key in config/filesystems.php to the name of the disk you want Laravel to use by default, like 'local' or 's3'.
Click to reveal answer
intermediate
What environment variable is commonly used to configure the default filesystem disk?
The FILESYSTEM_DISK environment variable is used to set the default disk dynamically without changing code.
Click to reveal answer
beginner
Name two common drivers used in Laravel filesystem disks and what they represent.
1. local driver: stores files on the server's local disk. 2. s3 driver: stores files on Amazon S3 cloud storage.
Click to reveal answer
Where do you define storage disks in Laravel?
AIn <code>config/filesystems.php</code>
BIn <code>routes/web.php</code>
CIn <code>app/Http/Controllers</code>
DIn <code>resources/views</code>
✗ Incorrect
Storage disks are configured in the config/filesystems.php file.
Which environment variable sets the default filesystem disk?
AAPP_ENV
BCACHE_DRIVER
CFILESYSTEM_DISK
DDB_CONNECTION
✗ Incorrect
The FILESYSTEM_DISK variable controls the default disk used by Laravel.
What driver would you use to store files on Amazon S3?
Adatabase
Bftp
Clocal
Ds3
✗ Incorrect
The s3 driver connects Laravel to Amazon S3 cloud storage.
If you want to store files on your server's hard drive, which driver should you choose?
Arackspace
Blocal
Cs3
Dftp
✗ Incorrect
The local driver stores files on the server's local disk.
How can you add a new storage location in Laravel?
AAdd a new disk entry in <code>config/filesystems.php</code>
BCreate a new route in <code>routes/web.php</code>
CAdd a new controller method
DModify the <code>app/Models/User.php</code> file
✗ Incorrect
New storage locations are added by defining new disks in config/filesystems.php.
Explain how Laravel uses the filesystem configuration to manage file storage.
Think about how Laravel knows where and how to save files.
You got /4 concepts.
Describe the steps to add a new cloud storage disk in Laravel.
Focus on configuration and environment setup.
You got /4 concepts.
Practice
(1/5)
1. What is the purpose of the default key in Laravel's config/filesystems.php file?
easy
A. It sets the default storage disk Laravel uses for file operations.
B. It defines the maximum file size allowed for uploads.
C. It specifies the encryption method for stored files.
D. It lists all available storage disks in the application.
Solution
Step 1: Understand the role of the default key
The default key in config/filesystems.php tells Laravel which disk to use when no specific disk is mentioned.
Step 2: Compare with other options
Options A, B, and C describe unrelated settings. Only "It sets the default storage disk Laravel uses for file operations." correctly describes the default disk setting.
Final Answer:
It sets the default storage disk Laravel uses for file operations. -> Option A
Quick Check:
Default disk = storage location [OK]
Hint: Default disk means where files go if no disk specified [OK]
Common Mistakes:
Confusing default disk with file size limits
Thinking default sets encryption
Assuming default lists all disks
2. Which of the following is the correct syntax to define a local disk in config/filesystems.php?
easy
A. 'local' => ['driver' => 'ftp', 'root' => storage_path('app')],
B. 'local' => ['driver' => 'local', 'root' => storage_path('app')],
C. 'local' => ['driver' => 's3', 'root' => storage_path('app')],
D. 'local' => ['driver' => 'local', 'root' => public_path('app')],
Solution
Step 1: Identify the correct driver for local disk
The local disk uses the 'local' driver, so options with 'ftp' or 's3' are incorrect.
Step 2: Check the root path for local storage
The root path for local disk is usually storage_path('app'), not public_path('app').
What happens when you call Storage::put('file.txt', 'Hello') in your app?
medium
A. An error occurs because the local disk is not set.
B. The file is saved to the local storage folder.
C. The file is saved to the configured Amazon S3 bucket.
D. The file is saved to a temporary directory.
Solution
Step 1: Identify the default disk
The default disk is set to 's3', so all Storage calls use the S3 disk unless specified otherwise.
Step 2: Understand Storage::put behavior
Calling Storage::put saves the file to the default disk, which is the S3 bucket configured.
Final Answer:
The file is saved to the configured Amazon S3 bucket. -> Option C
Quick Check:
Default disk 's3' means files go to S3 [OK]
Hint: Default disk controls Storage::put location [OK]
Common Mistakes:
Assuming file saves locally despite default 's3'
Thinking missing local disk causes error
Confusing temporary directory with storage
4. You added a new disk in config/filesystems.php but get an error when using it. Which of these is the most likely cause?
medium
A. You forgot to run php artisan config:cache after changing the config.
B. You used the wrong PHP version for Laravel.
C. You did not install the Laravel UI package.
D. You set the disk name to 'default' instead of a unique name.
Solution
Step 1: Understand Laravel config caching
Laravel caches config files for performance. Changes in config files require clearing or caching again.
Step 2: Identify the common fix
Running php artisan config:cache refreshes the cached config and applies new disk settings.
Final Answer:
You forgot to run php artisan config:cache after changing the config. -> Option A
Quick Check:
Config cache must refresh after edits [OK]
Hint: Run config:cache after config changes [OK]
Common Mistakes:
Ignoring config cache after edits
Blaming PHP version for config errors
Confusing unrelated packages with filesystem config
5. You want to configure a new disk in config/filesystems.php that stores files on a remote FTP server. Which of these is the correct minimal configuration?