Bird
Raised Fist0
Laravelframework~20 mins

Filesystem configuration in Laravel - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Filesystem Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
1:30remaining
What is the default disk used by Laravel's filesystem?
Given the default Laravel filesystem configuration, which disk will be used when calling Storage::disk() without any parameters?
A"public"
B"s3"
C"local"
D"ftp"
Attempts:
2 left
💡 Hint
Check the config/filesystems.php file for the default key.
📝 Syntax
intermediate
2:00remaining
Which configuration snippet correctly defines an S3 disk in Laravel?
Select the correct Laravel filesystem configuration array for an S3 disk.
A"s3" => ["driver" => "local", "key" => env("AWS_ACCESS_KEY_ID"), "secret" => env("AWS_SECRET_ACCESS_KEY"), "region" => env("AWS_DEFAULT_REGION"), "bucket" => env("AWS_BUCKET")]
B"s3" => ["driver" => "ftp", "key" => env("AWS_ACCESS_KEY_ID"), "secret" => env("AWS_SECRET_ACCESS_KEY"), "region" => env("AWS_DEFAULT_REGION"), "bucket" => env("AWS_BUCKET")]
C])"TEKCUB_SWA"(vne >= "tekcub" ,)"NOIGER_TLUAFED_SWA"(vne >= "noiger" ,)"YEK_SSECCA_TERCES_SWA"(vne >= "terces" ,)"DI_YEK_SSECCA_SWA"(vne >= "yek" ,"3s" >= "revird"[ >= "3s"
D"s3" => ["driver" => "s3", "key" => env("AWS_ACCESS_KEY_ID"), "secret" => env("AWS_SECRET_ACCESS_KEY"), "region" => env("AWS_DEFAULT_REGION"), "bucket" => env("AWS_BUCKET")]
Attempts:
2 left
💡 Hint
The driver for S3 must be exactly "s3" and keys must be named correctly.
🔧 Debug
advanced
2:30remaining
Why does this Laravel filesystem configuration cause an error?
Consider this snippet from config/filesystems.php:
"disks" => [
  "backup" => [
    "driver" => "local",
    "root" => storage_path("app/backups")
  ]
]
When trying to store a file using Storage::disk('backup')->put('file.txt', 'data');, an error occurs. What is the most likely cause?
AThe <code>storage/app/backups</code> directory does not exist and the local driver <code>put()</code> method does not automatically create directories.
BThe <code>root</code> path must be an absolute path string, not a function call.
CThe <code>driver</code> value "local" is invalid and should be "filesystem".
DThe disk name "backup" is reserved and cannot be used.
Attempts:
2 left
💡 Hint
Consider whether the put() method creates necessary directories if they don't exist.
❓ state_output
advanced
1:30remaining
What is the output of this Laravel filesystem code snippet?
Given the following code snippet, what will be the output?
use Illuminate\Support\Facades\Storage;

Storage::fake('avatars');
Storage::disk('avatars')->put('user1.png', 'imagecontent');

return Storage::disk('avatars')->exists('user1.png') ? 'Found' : 'Not Found';
ASyntax error due to missing import
B"Found"
CRuntime error because fake disk is not writable
D"Not Found"
Attempts:
2 left
💡 Hint
The Storage::fake() method creates a temporary disk for testing.
🧠 Conceptual
expert
3:00remaining
How does Laravel determine the URL for a file stored on the "public" disk?
Laravel's "public" disk is configured with driver => "local" and root => storage_path('app/public'). How does Laravel generate the public URL for a file stored on this disk when calling Storage::disk('public')->url('file.jpg')?
AIt returns the URL by prefixing the file path with the value of the <code>APP_URL</code> environment variable plus "/storage/" because the <code>public/storage</code> folder is linked to <code>storage/app/public</code>.
BIt returns the absolute file system path on the server where the file is stored.
CIt returns a signed temporary URL valid for 5 minutes by default.
DIt returns the URL by prefixing the file path with "/public/" directly without considering environment variables.
Attempts:
2 left
💡 Hint
Think about the symbolic link created by php artisan storage:link.

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

  1. 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.
  2. 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.
  3. Final Answer:

    It sets the default storage disk Laravel uses for file operations. -> Option A
  4. 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

  1. Step 1: Identify the correct driver for local disk

    The local disk uses the 'local' driver, so options with 'ftp' or 's3' are incorrect.
  2. Step 2: Check the root path for local storage

    The root path for local disk is usually storage_path('app'), not public_path('app').
  3. Final Answer:

    'local' => ['driver' => 'local', 'root' => storage_path('app')], -> Option B
  4. Quick Check:

    Local driver + storage_path = correct syntax [OK]
Hint: Local disk uses 'local' driver and storage_path root [OK]
Common Mistakes:
  • Using wrong driver like 'ftp' or 's3' for local disk
  • Setting root to public_path instead of storage_path
  • Mixing driver and root paths
3. Given this config/filesystems.php snippet:
'disks' => [
    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],
],
'default' => 's3',

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

  1. Step 1: Identify the default disk

    The default disk is set to 's3', so all Storage calls use the S3 disk unless specified otherwise.
  2. Step 2: Understand Storage::put behavior

    Calling Storage::put saves the file to the default disk, which is the S3 bucket configured.
  3. Final Answer:

    The file is saved to the configured Amazon S3 bucket. -> Option C
  4. 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

  1. Step 1: Understand Laravel config caching

    Laravel caches config files for performance. Changes in config files require clearing or caching again.
  2. Step 2: Identify the common fix

    Running php artisan config:cache refreshes the cached config and applies new disk settings.
  3. Final Answer:

    You forgot to run php artisan config:cache after changing the config. -> Option A
  4. 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?
hard
A. 'ftp' => [ 'driver' => 's3', 'key' => env('FTP_KEY'), 'secret' => env('FTP_SECRET') ],
B. 'ftp' => [ 'driver' => 'local', 'root' => env('FTP_HOST') ],
C. 'ftp' => [ 'driver' => 'ftp', 'bucket' => env('FTP_BUCKET') ],
D. 'ftp' => [ 'driver' => 'ftp', 'host' => env('FTP_HOST'), 'username' => env('FTP_USERNAME'), 'password' => env('FTP_PASSWORD') ],

Solution

  1. Step 1: Identify the correct driver for FTP

    The driver must be 'ftp' to connect to an FTP server, so options with 'local' or 's3' are incorrect.
  2. Step 2: Check required connection details

    FTP requires host, username, and password. 'ftp' => [ 'driver' => 'ftp', 'host' => env('FTP_HOST'), 'username' => env('FTP_USERNAME'), 'password' => env('FTP_PASSWORD') ], includes these minimal required keys.
  3. Final Answer:

    'ftp' => [ 'driver' => 'ftp', 'host' => env('FTP_HOST'), 'username' => env('FTP_USERNAME'), 'password' => env('FTP_PASSWORD') ], -> Option D
  4. Quick Check:

    FTP driver + host, username, password needed [OK]
Hint: FTP disk needs driver 'ftp' and host, user, password [OK]
Common Mistakes:
  • Using wrong driver like 'local' or 's3' for FTP
  • Missing required host or credentials
  • Confusing bucket with FTP config
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