Complete the code to apply middleware to a controller method.
public function __construct()
{
$this->middleware('[1]');
}The auth middleware is commonly used to restrict access to authenticated users in Laravel controllers.
Complete the code to apply middleware only to the 'show' method.
public function __construct()
{
$this->middleware('auth')->only('[1]');
}The only method limits middleware to specified controller methods. Here, it applies only to the 'show' method.
Fix the error in applying middleware to exclude the 'index' method.
public function __construct()
{
$this->middleware('auth')->except('[1]');
}The except method excludes the specified method from middleware. To exclude the 'index' method, use 'index'.
Fill both blanks to apply 'auth' middleware only to 'edit' and 'update' methods.
public function __construct()
{
$this->middleware('[1]')->only('[2]', 'update');
}The 'auth' middleware restricts access to authenticated users. Using only('edit', 'update') applies it to those methods.
Fill all three blanks to apply 'throttle' middleware with limit '60,1' except for 'index' and 'show' methods.
public function __construct()
{
$this->middleware('[1]:[2]')->except('[3]', 'show');
}The 'throttle' middleware limits request rate. Here, '60,1' means 60 requests per minute. The except excludes 'index' and 'show' methods.