I have a whereHas query which gets data from a pivot table. But on the pivot table i also have a extra column called 'order' and i use this column to make sure the items are ordered in the correct SEQUENCE as it represents a bus route. Ex: Bus/Ferry stops at 1 2 3 4 5 6.
We have a departure and destination point which are represented as 'port_id'.
So for example the below query gives me the correct data but i need to make sure that the 'order' column is always in the correct sequence based on the departure port id and the arrival port id. So if you would search for port_id 14 to port_id 15 it should not return any results as the 'order' column is not connecting those in that way.
This is what i've tried:
$routes = Route::whereHas('ports', function($query) use ($request) {
$query->where('port_id', $request->route['from']['id']);
})
->whereHas('ports', function($query) use ($request) {
$query->where('port_id', $request->route['to']['id']);
})->get();
Thank you.

