Laravel错误“模型/模型名称的声明应与Illuminate \ Database \ Eloquent \ Model兼容". [英] Laravel error "Declaration of model/model_name should be compatible with Illuminate\Database\Eloquent\Model"

查看:716
本文介绍了Laravel错误“模型/模型名称的声明应与Illuminate \ Database \ Eloquent \ Model兼容".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对有关laravel应用的一个奇怪的问题.在生产服务器上更新Composer之后,出现此错误.我的登录页面显示正常,当我输入凭据时,它显示此错误,或者凭据错误或对,它始终显示相同的错误.

错误是

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

我在互联网上进行了搜索,但一无所获.请帮忙.会很感激的.

解决方案

从父类覆盖方法时-方法的签名就参数及其类型而言必须完全相同/p>

在父类中,$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);
    }
    ...
}

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.

解决方案

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);
    }
    ...
}

这篇关于Laravel错误“模型/模型名称的声明应与Illuminate \ Database \ Eloquent \ Model兼容".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆