Relationship Methods for Contact Model
This snippet defines the relationship methods in a Contact model for an ORM system. It shows how to set up a many-to-many relationship with the Company model and a one-to-many relationship with the CompanyContact model, including pivot attributes and timestamps.unknown
php
17 days ago
396 B
5
Indexable
Never
/** * The companies that belong to the contact */ public function companies(): BelongsToMany { return $this->belongsToMany(Company::class) ->as('company_contact') ->using(CompanyContact::class) ->withPivot('is_point_of_contact', 'roles') ->withTimestamps(); } public function companyContacts(): HasMany { return $this->hasMany(CompanyContact::class); }
Leave a Comment