Ich brauche nach Abfrage von SQL mit Eloquent erhalten, erstellen groupBy('date')
und sortBy('price')
mit collect
in Laravel 5.3
.Wie sortBy nach groupBy in Collect in Laravel 5.3 zu verwenden?
In IndexController
:
$flights = Flights::GetFlights($fromCity, $toCity, $fromDate);
$collection = collect($flights);
$sortFlight = $collection->groupBy('date')->sortBy('price');
In Model
:
public function scopeGetFlights($query, $fromCity, $toCity, $fromDate)
{
// Between dates
$beforeDate = date('Y-m-d', strtotime($fromDate . '- 10 days'));
$afterDate = date('Y-m-d', strtotime($fromDate . '+ 10 days'));
$join = $query
-> join('airlines', 'airlines.pana', 'flights.airline')
-> where('flights.from_city', $fromCity)
-> where('flights.to_city', $toCity)
-> whereBetween('flights.date', [$beforeDate, $afterDate])
-> get([
'flights.*',
'airlines.pana as pana',
'airlines.name as airlineName'
]);
return $join;
}
Dann Print_r($sortFlight)
, groupBy('date')
Nach Druck ist funktioniert aber sortBy('price')
funktioniert nicht !!!!
Wo ist mein Problem?
Hallo @Punit .. So verwenden Sie 'sortBy ('flights.price')' in collect? – mySun