Ich führe eine einfache Abfrage aus, aber aus irgendeinem Grund gibt es mir nicht die richtige Ausgabe.Laravel 5.2 - Einfache Auswahl Abfrage gibt leeres Array zurück
Der Benutzer soll mehrere Antworten auf eine Frage durch Kontrollkästchen geben. Mit diesen Antworten versuche ich, die IDs von ihnen aus meiner DB zu bekommen.
Hier ist der Code, den ich mit:
foreach($foodtrucktypes as $foodtrucktype)
{
$type_id = DB::table('foodtruck_types')
->select('id')
->where('type', '= ', $foodtrucktype)
->get();
echo $foodtrucktype."<br />";
var_dump($type_id);
echo "<br />";
echo "<br />";
}
foreach($locations as $location)
{
$location_id = DB::table('locations')
->select('id')
->where('name', '=', $location)
->get();
echo $location."<br />";
var_dump($location_id);
echo "<br />";
echo "<br />";
}
foreach($partytypes as $partytype)
{
$party_id = DB::table('party_types')
->select('id')
->where('party_type' ,'=', $partytype)
->get();
echo $partytype."<br :>";
var_dump($party_id);
echo "<br />";
echo "<br />";
}
und das ist die Antwort, die ich erhalten:
Comfort Food array (0) {}
Desserten array (0) {}
Fastfood-Array (0) {}
Henegouwen-Array (1) {[0] => Objekt (stdClass) # 195 (1) {[ "id"] => int (2) }}
Limburg-Array (1) {[0] => objekt (stdClass) # 196 (1) {["id"] => int (3)}
Bedrijfsfeest array (1) {[0] => objekt (stdClass) # 194 (1) {[ "id"] => int (1)}}
Communiefeest-Array (1) {[0] => Objekt (stdClass) # 197 (1) {[ "id"] = > int (2)}}
So funktioniert der Code, mit Ausnahme der ersten foreach (foodtruck Typen), es leere Arrays zurück und ich kann nicht sehen warum.
Danke, das hat funktioniert! – Nicolas