dimanche 13 décembre 2020

How to sort Data based on relation ship column in laravel?

I am getting data in this format and i want to sort it porduct_machine.cost column

business_logo: "1607853198.jpeg"
business_phone: "0422429136"
comission: 89
distance: "1600 KM"
email: "bilahlarshad21041@gmail.com"
id: 3
latitude: "19.7059504"
location: "Morelia, Michoacán, Mexico"
longitude: "-101.1949825"
name: "Testing product"
opinion_compliment: "1607853198.png"
owner_email: "admin@adjjkmin.com"
owner_name: "abc"
owner_phone: "0422429136"
password: "$2y$10$p8hPKcatkVEVEX9rreXRQuUAX0uGZjjc3WmJnSCYY8BJFk9G468ya"
phone: ""
provider_machine: [{machine_id: 1, provider_id: 3, cost: 9, created_at: null, updated_at: null}]
0: {machine_id: 1, provider_id: 3, cost: 9, created_at: null, updated_at: null}
rfc: "sasa"
sat_document: "1607853198.png"
status: 1
tax: 212

``porduct_machine``` is hasMany relation.

I was trying to sort it in that way

$providers = Provider::get();

$providers =   $providers->sortBy('provider_machine.cost');

I must need to sort after get() . because there are multiole queries between that i just skipped in question



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LoYJnu
via IFTTT

Aucun commentaire:

Enregistrer un commentaire