omrakhurs
2 years ago

Possible to have a hasMany as well as a hasOne relationship with the same model?

Posted 2 years ago by omrakhurs

I've got a Company model in which I would like to define two relationships with the User model:

  public function users(){
     return $this->hasMany('App\User');
  }

  public function administrator(){
     return $this->hasOne('App\User', 'superuserid');
  }

I have a superuserid field in my companies table in the database, which is a foreign key to the id of the users table.

I just want to know if this is at all a good strategy or even possible?

Please sign in or create an account to participate in this conversation.