This is my controller
function index()
{
$name_list = DB::table('customers')
->groupBy('first_name')
->get();
$name_list2 = DB::table('customers')
->where('first_name', $name_list)->first();
return view('dynamic_field')->with('name_list2',$name_list2);
}
This is my view i am retriving this in javascript.
@foreach($name_list2 as $name)
'<option value="{{ $name->first_name}}">{{ $name->first_name }}</option>'+
@endforeach
first().It will take only one entry..So don't need to useforeach()in view.foreachused when you have a collection to print..$name_listto view,you could have to useforeach()..But in case of$name_list2no need offoreach()