未定义的变量:data(查看:C:\ cygwin64 \ home \ hp \ AddressBook esources \ views \ Update \ edit.blade.php)

My dynamic drop down list is not working when I am trying to navigate to update page by using url id and then its showing errors.The result suppose to be a name of city that is associated with id in the database.

controller class

public function updateAddress($edit_id)
  { 
         $data=[];
         $data['edit_id']=$edit_id;
         $address_data = $this->address->find($edit_id);
         $data['first_name']=$address_data->first_name;
         $data['last_name']=$address_data->last_name;
         $data['street']=$address_data->street;
         $data['zip_code']=$address_data->zip_code;
         $data['city']=$address_data->city;


   return view('update/edit',$data);

  }

Here is my blade file. The rest of the fields are working properly except drop down list. I am using foreach loop to display data into the drop down list.

 <select id="city" name="city" >

 @foreach($data as $cities)

<option id="city" value="{{$cities->edit_id}}" selected="selected">{{$cities->city}}</option>

@endforeach

 </select>

Update the code in the controller so that:

return view('update/edit',$data);

Is changed to:

return view('update/edit', ['data' => $data]);

change your controller code to

return view('update/edit',compact('data'));

and change your view page like {{ $data['edit_id'] }}. you dont want to use @foreach.