Just use first() on your companies collection.
Jun 8, 2021
2
Level 5
Get single model from relation with pivot table
I have 3 tables "users", "companies" and the pivot table "company_user". For now a user has to a single company I have a relation in User model called companies() that is a "belongsToMany" this return a collection of companies but I want to have a relation called company that returns a single company model, I can achieve this using a custom query but maybe there are any method provided by laravel framework that can helping me with that.
Any ideas how to achieve this?
Please or to participate in this conversation.