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
Tag: relationship
Error Call to a member function attach() on null
I want to create tag system but I have an error “Error Call to a member function attach() on null “. Look at my code Relationship: Job.php public function services(){ $this->…
how to retrieve data from laravel relationship?
Hello im trying to do a quiz app with laravel and im struggeling with retrieving my questions with category.. i have a unsightly solution with this but it’s not dynamically.. public function …
Relationship with the same table (Many to Many?) – Laravel
In my database I have to save people and the data of people that have a relationship with the first. For example: father, mother, son, daughter, etc Then the design of the database, I did it in the following way Is a relation many-to-many because, a person have many people related to it. But I’m not sure if is ok..
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 5.1 – BelongsTo relationship returns null
AppUser class User public function status() { return $this->belongsTo(‘AppUserStatus’, ‘user_status_id’, ‘id’); } AppUserStatus class UserStatus protected $fillable = [‘id’]; public …
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