Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shri's avatar
Level 1

How to fetch data on multiple dropdown in laravel 5.8?

I want to fetch multiple dropdown data from database how to do in laravel?

there are three table

  1. employee ( id, f_name, l_name)
  2. hobby (id, hobby_name)
  3. employee_hobby ( id , emp_id, hobby_id);

emp_id and hobby_id are foreign key, from form i am storing data into employee_hobby on the data is in id form so how to fetch?

0 likes
2 replies
shri's avatar
Level 1
Select hobby {{ $results = DB::table('hobby_view')->where('emp_id', $data->id)->get() @if(!$results->isEmpty()) $hb = array(); $i=0; @while($hobby = $results->fetch()) $hb[$i] = $hobby['hobby_name']; $i++; @endwhile @endif }} {{ $stmt = DB::select("select * from hobby") @while($rowhobby = $stmt -> fetch()) $hobby = print_r($rowhobby['hobby_name'], true); }} {{ $hobby }} {{@endwhile}}

this is php code i want this concept in laravel to fetch the data into dropdown how i can do? i tried but it's show so much syntax error?

shri's avatar
Level 1

@while($hobby = $results->fetch()) $hb[$i] = $hobby['hobby_name']; $i++; @endwhile

is there any problem with while loop

Please or to participate in this conversation.