Back

Model split response on column true.


I have a query that I was previously calling with Quote::with(['detail.orders'])->findOrFail($id);

Which works just fine, however, the orders table now has a column 'is_primary' that I wish to split the response on, (i.e, select where is_primary = 'true').

With this new column, I wish to build a query that would generate a response like;

{
	"detail": {
		"primary_orders": [{...}],
		"secondary_orders": [{...}]
	}
}

Is this possible through the query builder?

Thanks

(Postgresql 9.3)

Edit :

I do have this;

Quote::with([
                'detail.primaryOrders' => function($query) {
                    $query->where('is_primary', '=', 'true');
                },
                'detail.secondaryOrders' => function($query) {
                    $query->where('is_primary', '=', 'false');
                }])->findOrFail($id);

But as with many things related to Eloquent, my understanding of the builder is limited and I'm not sure if this is entirely optimal

Cameron replied 1 week ago

Maybe a model resource could come in handy here ? It may allow you to make different requests for primary and secondary but let you put them in one response

吴笛 replied 1 week ago

阿斯顿发松岛枫

MorganRichard replied 1 week ago

An AI calculation is to part the information into preparing and testing subsets. Keep in mind, AI is tied in with encouraging PCs to play out an errand by demonstrating to it a ton of precedents. We'll instruct the PC using the information we have accessible Write My Essay For Me, however in a perfect world the calculation will work similarly too with new information.


Sign in to participate in this thread!



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