Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to cache a view in Laravel.
Laravel
return view('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cache' instead of the view name.
Confusing route names with view names.
✗ Incorrect
The view() function loads a Blade template by its name, such as 'welcome'.
2fill in blank
mediumComplete the command to cache all views in Laravel.
Laravel
php artisan [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'config:cache' which caches config files, not views.
Using 'cache:clear' which clears caches instead of creating them.
✗ Incorrect
The php artisan view:cache command compiles and caches all Blade views for faster loading.
3fill in blank
hardFix the error in the command to clear cached views.
Laravel
php artisan [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cache:clear' which clears all caches, not just views.
Using 'view:cache' which caches views instead of clearing.
✗ Incorrect
The correct command to clear cached views is php artisan view:clear.
4fill in blank
hardFill both blanks to create a cached view with data.
Laravel
return view('[1]')->with('[2]', $data);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up view names and variable keys.
Using variable names that don't match the data passed.
✗ Incorrect
This code returns the 'dashboard' view and passes data under the key 'user'.
5fill in blank
hardFill all three blanks to cache a view with a condition.
Laravel
return view('[1]')->with('[2]', $data)->when($data->count() [3] 0, fn() => cache()->remember('view_cache', 60, fn() => $data));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for the condition.
Passing wrong variable names to the view.
✗ Incorrect
This code returns the 'reports' view with 'items' data and caches it if the count is greater than 0.