0

I want to store a model id in same table with different column rel_id having a relation with the id column, but the relation hasOne not working, showing this error:

Cannot redeclare App\Models\Employee:supervisor()

class Employee extends Model
{   
    function supervisor()
    {
        return $this->hasOne('App\Models\Employee','id', 'supervisor_id');
    }
}
  • 2
    Show us your model. – Ohgodwhy Jun 10 '18 at 05:59
  • I think he meant show us the model where the failed function is coded -- the failure message talks to RelFunction(), not supervisor(). Most likely you have two RelFunctions in the model or a related model. Do a search on this and let us know if this is the case. – Watercayman Jun 10 '18 at 15:16

1 Answers1

0

Its really hard to tell without a little more information and a more complete model posted, but the two most likely causes are:

  1. You have two of the same methods (RelFunction()) on your model, or another model with the same namespace. Do a search in your code (first your model, then globally) for RelFunction.
  2. You have a namespacing problem. You may have copied a model, or moved it to a new folder, or just incorrectly namespaced it. Depending on what the model looks like in detail, this could inadvertently cause the error message.
Watercayman
  • 7,970
  • 10
  • 31
  • 49