Ramnik, pluck() retrieves all of the values for a given key. If you pass 2 values in the pluck(), it will return key => value pairs. So in your example you can retrive both columns like this
public function getMaterialBySection($section){
$filteredMaterials = Section::with('materials')
->where('id', $section)
->get()
->pluck('materials.*.name', 'materials.*.id');
return json_encode($filteredMaterials);
}
$data = json_decode(getMaterialBySection($section));
foreach($data as $id => $name){
}