0
0
Laravelframework~10 mins

Config files and access in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of 'app.name' from the config.

Laravel
$appName = config('[1]');
Drag options to blanks, or click blank then click option'
Acache.default
Bapp.name
Cdatabase.connections.mysql
Dmail.driver
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong config key like 'database.connections.mysql' instead of 'app.name'.
Forgetting to put the key as a string.
2fill in blank
medium

Complete the code to set the cache driver to 'redis' in the config at runtime.

Laravel
config(['cache.default' => [1]]);
Drag options to blanks, or click blank then click option'
A'redis'
B'database'
C'file'
D'memcached'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the driver name.
Using a driver name that is not supported.
3fill in blank
hard

Fix the error in accessing the database host from config.

Laravel
$dbHost = config('[1]');
// Expected to get '127.0.0.1' from config/database.php
Drag options to blanks, or click blank then click option'
Adatabase.host
Bconnections.mysql.host
Cdatabase.mysql.host
Ddatabase.connections.mysql.host
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'database.host' which does not exist.
Using incomplete keys missing 'connections.mysql'.
4fill in blank
hard

Fill both blanks to get the mail driver and set it to 'smtp' at runtime.

Laravel
$mailDriver = config('[1]');
config(['[2]' => 'smtp']);
Drag options to blanks, or click blank then click option'
Amail.driver
Bmail.default
Cmail.mailer
Dmail.transport
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mail.driver' which is not the correct key in Laravel 8+.
Using different keys for get and set.
5fill in blank
hard

Fill all three blanks to create a config array with keys 'app.env', 'app.debug', and 'app.url'.

Laravel
$settings = [
  '[1]' => config('[2]'),
  '[3]' => config('app.url')
];
Drag options to blanks, or click blank then click option'
Aapp.env
Bapp.debug
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing keys and values incorrectly.
Using keys that don't exist in config.