3 months ago

take(1) applying to all related models

Posted 3 months ago by megaman

I have the following query (note this is pesudo code since the real code is on a different machine which i cant get to right now)

Customer::where('gender','=','female')->with(['order' => function($q){ $q->take(1) });

I expected this to return only 1 order for each customer. Instead its returning 1 order total ( no matter how many separate customers there are)

Is this a glitch or am i doing something wrong

Please sign in or create an account to participate in this conversation.