Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Laravel 5 UnexpectedValueException als Antwort auf Abfrage aufgrund der Verwendung von POINT-Daten

Ich denke, ich sollte mehr Fragen stellen, bevor ich diese Antwort poste, aber ich denke, Sie machen die Dinge in der falschen Reihenfolge.

public function rentals($id)
{
    // Retrieve all rentals within a region and the locations spatial data
    $rentals = DB::table('rentals')
                 ->join('regions', 'rentals.region_id', '=', 'regions.id')
                 ->join('rental_locations', 'rentals.rental_location_id', '=', 'rental_locations.id')
                 ->select('*')
                 ->where('rentals.region_id', '=', $id)
                 ->groupBy('rental_location_id')
                 ->get();


    return collect($rentals); // or return $rentals
/* Not necessary
    // Create a collection from the array of query results
    $rentals = collect($rentals);


    // Laravel is set up to return collections as json when directly returned
    return $rentals;
*/
}

Sie müssen also Ihre groupBy in der Abfrage selbst hinzufügen, da dies eine Abfrageaktion ist, die Ihr SQL ausführen sollte. Der andere Teil ist, dass Sie es einfach zurückgeben können, wenn Sie es in eine Sammlung umwandeln (was nicht 100% notwendig ist). Laravel verarbeitet JSON nativ.