Bird
0
0

Given this controller constructor code:

medium📝 component behavior Q4 of 15
Laravel - Controllers
Given this controller constructor code:
public function __construct() {
    $this->middleware('auth')->except(['index', 'show']);
}

Which methods will NOT require authentication middleware?
Aonly index requires authentication
Bindex and show
Call methods require authentication
Dno methods require authentication
Step-by-Step Solution
Solution:
  1. Step 1: Understand except() method in middleware

    The except() method excludes listed methods from middleware application.
  2. Step 2: Identify excluded methods

    Here, 'index' and 'show' are excluded, so they do not require authentication.
  3. Final Answer:

    index and show -> Option B
  4. Quick Check:

    except() excludes methods from middleware [OK]
Quick Trick: Use ->except() to exclude methods from middleware [OK]
Common Mistakes:
  • Assuming except() applies middleware only to listed methods
  • Confusing except() with only()
  • Thinking all methods require middleware despite except()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes