My preferences is always relationships. Your case too.
You can easily implement pivot table based relationship here.
Ref: https://laravel.com/docs/5.5/eloquent-relationships#defining-relationships
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys. I am still learning laravel, and OOP for that matter, but am catching on quickly. I am working on a system that has two controllers. Organizations, and Employees. There is an interim table called employees_organizations that links employees to individual (or multiple) organizations.
One of the routes in the system is /organizations/{organization-id}/employees, which lists all of the employees linked to this organization.
What is the best way to handle linking these two together, so that I can effectively display how I want it to? I was originally going to use Eloquent Relationships, but since there are three tables, one being the lookup table, I am not sure how I can go about doing this.
The tables are setup like:
organizations- id, name, location
employees- id, name
employees_organizations- id, employee_id, organization_id
The reason for this, instead of just putting the organization id on the individual employee, is that an employee can have multiple organizations they are associated with. The lookup table was the best method for that at the time of design.
Any help would be greatly appreciated.
Please or to participate in this conversation.