PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] Laravel error "Declaration of model/model_name should be compatible with Illuminate\Database\Eloquent\Model"

 January 17, 2022     authentication, composer-php, laravel     No comments   

Issue

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.


Solution

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


Answered By - Yaron U.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,261,246

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing