mardi 17 mars 2020

Laravel - Undefined index in query builder

I have the following array which I want to pass all values for "main_id" key to whereNotIn condition:

array:7 [
  0 => array:1 [
    "main_id" => "KWS1354767"
  ]
  1 => array:1 [
    "main_id" => "KWS1348470"
  ]
  2 => array:1 [
    "main_id" => "KWS1300790"
  ]
  3 => array:1 [
    "main_id" => "KWS1267286"
  ]
  4 => array:1 [
    "main_id" => "KWS1260614"
  ]
  5 => array:1 [
    "main_id" => "KWS1259115"
  ]
  6 => array:1 [
    "main_id" => "KWS1145684"
  ]
]

My code in controller is the following:

$search = $search->select("properties.prop_id as main_id")->get();
$searcharray = $search->toArray();
$prop_cnt = DB::table("offerdemandsmatchs")->whereNotIn('prop_id', $searcharray['main_id'])
            ->where('offerdemand_id', $o->id)
            ->get();

The error I get is:

ErrorException  : Undefined index: main_id

If I manually pass the array it works:

$prop_cnt = DB::table("offerdemandsmatchs")->whereNotIn('prop_id', ['KWS1354767', 'KWS1348470', 'KWS1300790'])
           ->where('offerdemand_id', $o->id)
           ->get();

I can't get values from array and if I pass the values as in the first statement it fails. How can I pass array values as I'm doing it manually? Do I have to pass a collection?

Regards



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2IUSmDT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire