In this case, it would be better to use a regular table instead of a pivot table. A pivot table is used when you have a many-to-many relationship between two tables, and you need to store additional information about that relationship. In this case, you have a one-to-many relationship between Table A and Table C, and a one-to-many relationship between Table B and Table C.
To set up the relationships, you would use the following code:
// Table A model
class TableA extends Model
{
public function tableCs()
{
return $this->hasMany(TableC::class);
}
}
// Table B model
class TableB extends Model
{
public function tableCs()
{
return $this->hasMany(TableC::class);
}
}
// Table C model
class TableC extends Model
{
public function tableA()
{
return $this->belongsTo(TableA::class);
}
public function tableB()
{
return $this->belongsTo(TableB::class);
}
}
With this setup, you can easily access the related models:
$tableA = TableA::find(1);
$tableCs = $tableA->tableCs;
$tableB = TableB::find(1);
$tableCs = $tableB->tableCs;
$tableC = TableC::find(1);
$tableA = $tableC->tableA;
$tableB = $tableC->tableB;