Modal Relationships

Posted 4 years ago by Anotheruser

Hi, I just want to check what the correct way to accomplish the following is:

I have three Models - Company, Project, Contractor

  • A company can have multiple Project's

  • A project can have a single Contractor

Now when creating a new Project I would like to display a list of all Contractors that are already in the system and created by the Company. So as a Company I can go in and either create a new Contractor or select one that is already linked to my Company all be it through a project.

My question is - What is the correct way to make that link, i.e. to query the DB for all Contractors that have been created by my Company?

Currently in Project Model:

public function contractor() { return $this->hasOne('Contractor'); }

In Contractor Model:

public function project() { return $this->belongsTo('Project'); }

Im thinking that hasManyThrough() might work but my brain just isn't working properly this morning and I just cant process the doc's.

Thanks

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