php – controller variable not pass in view-ThrowExceptions

Exception or error:

I passed a Variable from my controller back to my view:

public function getdata()
  {
      $data = DB::table('treatments')->pluck("Treatment_name","Treatment_id");
      return view('layout.patient-list',compact('data'));
  }

but when I access this data on the view page

@foreach($data as  $row)
    <option value="{{ $row->Treatment_name }}">{{ $row->Treatment_name }}</option>
@endforeach

it give error undefined variable $data
how can solve it

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *