Laravel error “Declaration of model/model_name should be compatible with Illuminate\Database\Eloquent\Model”

这一生的挚爱 提交于 2019-12-24 19:29:29

问题


i am facing a strange issue regarding laravel application. after updating the composer on my production server i am getting this error. My login page showing fine and when i am entering the credentials its showing this error either the credentials wrong or right its always showing the same error.

Error is

Declaration of App\Models\User::update($a_data = NULL, $a_conditions = NULL) should be compatible with Illuminate\Database\Eloquent\Model::update(array $attributes = Array, array $options = Array)

i have searched on internet but found nothing. Please do help. will be thankful.


回答1:


When overriding a method from parent class - the signature of the method must be exactly the same in terms of parameters and their types

In the parent class, both $attributes and $options are set to be of type array, so you must also set set them this way in your class

namespace App\Models;

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


来源:https://stackoverflow.com/questions/54427395/laravel-error-declaration-of-model-model-name-should-be-compatible-with-illumin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!