Basically, I'm trying to use the following table structure in Eloquent. I have a polymorphic table that connects people to organizations. There are some sub organization tables and I gave the district one as an example that I want to connect Person to.
The thing to see here is that the OrganizationPerson.organization_id is pointing to the District.organization_id instead of District.id
Person
id
OrganizationPerson
id
person_id
organization_id
organization_type
District
id
organization_id
Organization
id
name
The table data would look like
Person
id => 1
OrganizationPerson
id => 4
person_id => 1
organization_id => 2
organization_type => 'District'
District
id => 3
organization_id => 2
Organization
id => 2
name => 'North Central District'
How would I get this to work?
class Person extends Model {
public function district()
{
return $this->morphTo(); // Something or whatever, how does it work?
}
}
Do I need to create a custom morphToOne or hasOneThrough
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community