Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Ha, well figured out why it didn't work. Without also selecting the key (id), Laravel/Eloquent had no idea what to bind the tables to. Removed the protected $with from the User model and then in the controller modified to this...

$collaborators = \App\User::with(['profilePicture' => function($query) {
   $query->select('url');
}])->select(['email','name','id'])->get();

Works like a charm now. Stumbled upon this as I tested the relationship getting with \App\User::all() which worked so figured it was something that I was chaining with constraints that muxed it, and lo and behold, bam.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

kenmoini kenmoini Joined 22 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.