Bird
0
0

Identify the error in this controller constructor:

medium📝 Debug Q14 of 15
Laravel - Controllers
Identify the error in this controller constructor:
public function __construct() {
    $this->middleware('auth')->except('index', 'show');
    $this->middleware('log');
}
AMiddleware 'log' will override 'auth' middleware
BYou cannot call middleware twice in constructor
Cexcept() method requires array, not multiple arguments
DNo error; both middleware apply correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check multiple middleware calls

    Laravel allows multiple middleware calls in constructor; they stack and apply in order.
  2. Step 2: Validate except() usage

    except() accepts multiple string arguments or an array; both are valid.
  3. Final Answer:

    No error; both middleware apply correctly -> Option D
  4. Quick Check:

    Multiple middleware calls and except() usage are valid = C [OK]
Quick Trick: Multiple middleware calls stack; except() accepts multiple args [OK]
Common Mistakes:
  • Thinking multiple middleware calls override each other
  • Assuming except() needs array only
  • Believing syntax causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes