Laravel 错误“模型/模型名称的声明应与 Illuminate\Database\Eloquent\Model 兼容”

Sha*_*ban 4 authentication laravel composer-php

我面临一个关于 Laravel 应用程序的奇怪问题。在我的生产服务器上更新作曲家后,我收到此错误。我的登录页面显示正常,当我输入凭据时,它显示此错误,无论凭据错误还是正确,它总是显示相同的错误。

错误是

App\Models\User::update($a_data = NULL, $a_conditions = NULL) 的声明应与 Illuminate\Database\Eloquent\Model::update(array $attributes = Array, array $options = Array) 兼容

我在互联网上搜索过但一无所获。请帮忙。会很感激。

Yar*_* U. 6

当从父类重写方法时 - 该方法的签名在参数及其类型方面必须完全相同

在父类中, 和$attributes$options设置为类型array,因此您也必须在您的类中以这种方式设置它们

namespace App\Models;

class User extends \Illuminate\Database\Eloquent\Model {
    ...
    public function update(array $attributes = [], array $options = []) {
       // ... your implementation
       return parent::update($attributes, $options);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)