Skip to content
Advertisement

Tag: relationship

How to get all data from a Eloquent Model with it’s relations?

My question is how to get the data from an eloquent model with its relation? Imagine 3 tables: users: companies: addresses: And the relations: Company.php User.php Address.php In this case how I can get let’s say all the companies with their related users and addresses? on Company::whereHas(‘users’)->get(); getting: Any thoughts? Thank you Answer The issue was that in the company

Laravel polymorphic with custom foreign key

I have problem with custom shipmentable_type. My structure looks like this: Now I have in my Transfer model realtion like this: The problem is, that to table shipmentable, to column shipmentable_type is going sth like this now: App/Models/Transfer, but I would like to force to be there ‘transfer’ in this case. Is it possible? Answer From the docs By default,

Laravel where on relationship object

I’m developing a web API with Laravel 5.0 but I’m not sure about a specific query I’m trying to build. My classes are as follows: and Now, I want to get all the events with a specific participant. I tried with: but the where condition is applied on the Event and not on its Participants. The following gives me an

Laravel Eloquent – Attach vs Sync

What is the difference between attach() and sync() in Laravel 4’s Eloquent ORM? I’ve tried to look around but couldn’t find anything! Answer attach(): Insert related models when working with many-to-many relations No array parameter is expected Example: sync(): Similar to the attach() method, the sync() method is used to attach related models. However, the main differences are: sync() accepts

Advertisement