Bird
0
0

Identify the error in this controller method:

medium📝 Debug Q6 of 15
Laravel - Controllers
Identify the error in this controller method:
public function update(Request $request, $id) {
    $user = User::find($id);
    $user->name = $request->input('name');
    $user->save;
    return redirect()->back();
}
AMissing parentheses on save method call
BIncorrect use of redirect()->back()
CRequest object should be passed by reference
DUser::find should be User::get
Step-by-Step Solution
Solution:
  1. Step 1: Check method calls

    The line $user->save; misses parentheses, it should be $user->save();.
  2. Step 2: Validate other parts

    redirect()->back() is correct, Request is passed correctly, User::find is valid.
  3. Final Answer:

    Missing parentheses on save method call -> Option A
  4. Quick Check:

    Method call syntax error [OK]
Quick Trick: Always use parentheses when calling methods [OK]
Common Mistakes:
  • Forgetting parentheses on method calls
  • Misusing redirect helpers
  • Confusing find with get

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes