Skip to content
Advertisement

Order by field in many to many relation (Laravel)

I have a model School wich has a belongsToMany relation:

JavaScript

How I can order school by event start_at field? For example, can I do like this?

JavaScript

Is it posible? Please tell me how to implement this. thanks.

UPD: I try with join, yes it works but not properly:

JavaScript

I’l geting all events. ->whereDate("events.start_at", ">=", Carbon::now()->format("Y-m-d")) not work, and not load addresses

Advertisement

Answer

Solution:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement