0
0
Laravelframework~10 mins

Query parameters 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 'id' query parameter from the request.

Laravel
$id = $request->[1]('id');
Drag options to blanks, or click blank then click option'
Ainput
Bquery
Cparam
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using input() instead of query() to get query parameters.
Using get() which is not a method on the request object.
2fill in blank
medium

Complete the code to check if the 'page' query parameter exists in the request.

Laravel
if ($request->[1]('page')) {
    // do something
}
Drag options to blanks, or click blank then click option'
Ahas
Bfilled
Ccontains
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using exists() which is not a Laravel request method.
Using contains() which is for collections, not request.
3fill in blank
hard

Fix the error in the code to get all query parameters as an array.

Laravel
$params = $request->[1]();
Drag options to blanks, or click blank then click option'
Aquery
Binput
Call
Dparams
Attempts:
3 left
💡 Hint
Common Mistakes
Using all() returns all input including POST data, not just query parameters.
Using params() which is not a Laravel request method.
4fill in blank
hard

Fill both blanks to get the 'sort' query parameter with a default value of 'asc'.

Laravel
$sort = $request->[1]('sort', [2]);
Drag options to blanks, or click blank then click option'
Aquery
B'asc'
C'desc'
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using input() instead of query() for query parameters.
Using 'desc' as default instead of 'asc'.
5fill in blank
hard

Fill all three blanks to filter query parameters where values are not empty strings.

Laravel
$filtered = collect($request->[1]())->filter(function($value) {
    return $value [2] '';
});

$filteredArray = $filtered->[3]();
Drag options to blanks, or click blank then click option'
Aquery
B!==
CtoArray
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using input() instead of query() to get parameters.
Using != instead of !== which is strict comparison.
Forgetting to convert collection back to array.