Home > database >  Undefied Array Key 'id' in Laravel
Undefied Array Key 'id' in Laravel

Time:07-11

I have an associative array in my controller. The code is :

$patient_indoor[] = array (
 

);

$patient_indoor[] = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);

When I try to print the value of the array in the blade file by the following code, It shows nothing. If I remove the @isset block, it says undefined Array key "id" . How can I fix the issue.

 @foreach($patient_indoor as $p) ?>
@isset($p['id'])
  <td>  {{$p['id']}} </td>
@endisset
@endforeach

CodePudding user response:

You defined $patient_indoor[] an array.

Replace it with $patient_indoor and it will be ok.

CodePudding user response:

$patient_indoor[] = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);

will return array as:

$patient_indoor[0][index]["id"]

Try this:

$patient_indoor = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);
  • Related