0
0
Laravelframework~10 mins

Controller middleware 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 apply middleware to a controller method.

Laravel
public function __construct()
{
    $this->middleware('[1]');
}
Drag options to blanks, or click blank then click option'
Aauth
Broute
Cview
Dcache
Attempts:
3 left
💡 Hint
Common Mistakes
Using middleware names that do not exist like 'route' or 'view'.
Forgetting to put the middleware name as a string.
2fill in blank
medium

Complete the code to apply middleware only to the 'show' method.

Laravel
public function __construct()
{
    $this->middleware('auth')->only('[1]');
}
Drag options to blanks, or click blank then click option'
Ashow
Bindex
Cedit
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing methods like 'index' or 'create' which are for listing or creating resources.
Not using quotes around the method name.
3fill in blank
hard

Fix the error in applying middleware to exclude the 'index' method.

Laravel
public function __construct()
{
    $this->middleware('auth')->except('[1]');
}
Drag options to blanks, or click blank then click option'
Aedit
Bindex
Cshow
Ddestroy
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding the wrong method like 'show' or 'edit'.
Not using quotes around the method name.
4fill in blank
hard

Fill both blanks to apply 'auth' middleware only to 'edit' and 'update' methods.

Laravel
public function __construct()
{
    $this->middleware('[1]')->only('[2]', 'update');
}
Drag options to blanks, or click blank then click option'
Aauth
Bguest
Cedit
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'guest' middleware which is for unauthenticated users.
Using wrong method names like 'show' instead of 'edit'.
5fill in blank
hard

Fill all three blanks to apply 'throttle' middleware with limit '60,1' except for 'index' and 'show' methods.

Laravel
public function __construct()
{
    $this->middleware('[1]:[2]')->except('[3]', 'show');
}
Drag options to blanks, or click blank then click option'
Athrottle
B60,1
Cindex
Dguest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'auth' or 'guest' instead of 'throttle' for rate limiting.
Incorrect method names in except list.