I'm new to laravel and eloquent and I'm not sure if this is even possible. but I have 2 tables with a one to many relationship. One is "locations" and one is "users". One location can have many users.
So if I wanted to get all locations with all users I would just do this:
Location::with("users")->get();
But I also want to know how many users each location has, I tried doing this
Location::with("users")->count("users")->get();
But that didn't work.
Location::with("users")->get();thenLocation::with("users")->count();might work, too. Have you tried that (I've just scanned the docs, never used that library)?. - hakrecount($location->relationships['users'])when you are looping trough the locations for example with aforeach ($locations as $location)Or you want to count all the users who has a location not for each? - TLGreg