How do I create a relation manager for a pivot table

Hello, I have a Container class and I have a Transporter class. i have a pivot table with transporter_id, container_id and price called container_transporter. I would like to manage the containers and price in the transporter resource. I have setup my models like this:
// In Container model
public function transporters()
{
return $this->belongsToMany(Transporter::class, 'container_transporter')
->withPivot('price');
}
// In Container model
public function transporters()
{
return $this->belongsToMany(Transporter::class, 'container_transporter')
->withPivot('price');
}
// In Transporter model
public function containers()
{
return $this->belongsToMany(Container::class, 'container_transporter')
->withPivot('price');
}
// In Transporter model
public function containers()
{
return $this->belongsToMany(Container::class, 'container_transporter')
->withPivot('price');
}
How do I set this up in the relationmanager?
2 Replies
codeartisan
codeartisan11mo ago
Hey did you get the solution to this
Sujal Tamrakar
Sujal Tamrakar11mo ago
I think you can use repeaters for this. - Add hasMany relationship model to pivot table. In your case, Transporter model should have something like :
public function transporterContainer()
{
return $this->hasMany(ContainerTransporter::class); // ContainerTransporter is model for pivot table
}
public function transporterContainer()
{
return $this->hasMany(ContainerTransporter::class); // ContainerTransporter is model for pivot table
}
- Use this relationship in repeater
Want results from more Discord servers?
Add your server