Call to undefined method Illuminate\Database\Query\Builder::save()

前端 未结 3 1607
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 06:53

I am trying to call Eloquent\'s save() method on an existing record but getting an error from Illuminate\'s Query Builder.

Following the documentation on Laravel\'s web

3条回答
  •  萌比男神i
    2021-02-07 07:12

    Apparently the ->get() method will not work with Eloquent's ->save() method and you must use ->first() instead.

    Correct: $this->employee = Employee::where('login', $login)->first();

    Incorrect: $this->employee = Employee::where('login', $login)->get();

    See http://laravel.io/forum/06-04-2014-symfony-component-debug-exception-fatalerrorexception-call-to-undefined-method-illuminatedatabaseeloquentcollectionsave for additional reference.

提交回复
热议问题