【问题标题】:Call to undefined method Illuminate\Auth\GenericUser::fill() :: when update调用未定义的方法 Illuminate\Auth\GenericUser::fill() :: 更新时
【发布时间】:2017-11-06 10:55:44
【问题描述】:

我要更新用户密码

这是我的功能:

public function modifiermdp(Request $request)
{
    $userupdate = Auth::user();
    $password = bcrypt($request['password']);
    $userupdate->fill(['password' => $password])->save();
    return Redirect::back()->with('message', 'تم التعديل بنجاح');
}

这是我的路线:

Route::prefix('/compte')->group(function() {
    Route::get('/', 'CompteController@index');
    Route::post('/changemdp', 'CompteController@modifiermdp');
});

我在 config/auth.php 中使用数据库驱动程序

'providers' => [
     'enseignant' => [
         'driver' => 'database',
         'table' => 'enseignant',
     ],
],

我收到这个错误

CompteController.php 第 38 行中的 FatalErrorException: 调用未定义的方法 Illuminate\Auth\GenericUser::fill()

【问题讨论】:

    标签: php database laravel laravel-5


    【解决方案1】:

    由于是数据库驱动,所以需要手动操作。

    \DB::table('enseignant')
        ->where('id', $user->getAuthIdentifier())
        ->update(['password' => $password]);
    

    【讨论】:

    • 同样的错误调用未定义的方法 Illuminate\Auth\GenericUser::forceFill()
    • 同样的错误 GenericUser::save() 当我使用 dd($userupdate) 我得到正确的信息 GenericUser {#403 ▼ #attributes: array:21 [▼ "id" => 1 "password " => "$2y$10$tWMBS0VEwt7gz.dmT1EHCoolV0lSFqn5dh2.YWJoReMcVNhnH89Dq" ] }
    • @cherire 刚刚检查了该类及其实现。当涉及到数据库驱动程序时,您似乎必须手动执行此操作。这是数据库驱动用户类public function updateRememberToken(UserContract $user, $token) { $this->conn->table($this->table) ->where('id', $user->getAuthIdentifier()) ->update(['remember_token' => $token]); }里面的方法之一
    • 谢谢 :) 我以前不知道,工作正常
    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 2016-06-25
    • 2017-07-14
    • 2020-07-06
    • 2015-09-23
    相关资源
    最近更新 更多