/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $terms = Term::orderBy('name', 'asc')->get();
     if ($request->ajax()) {
         return $terms;
     }
     return view('terms.index', compact('terms'));
 }
 public function getUserFormEdit($id)
 {
     if (!Auth::user()) {
         return redirect('/');
     }
     $decleration = Decleration::findOrNew($id);
     $fields = Field::orderBy('name')->lists('name', 'id');
     $terms = Term::orderBy('name')->lists('name', 'id');
     $listener_numbers = Listenernumber::all();
     $learn_methods = Learnmethod::all();
     $estimations = Estimation::all();
     $ratingsystems = Ratingsystem::all();
     $certificaterules = Certificaterule::all();
     $learnmaterials = Learnmaterial::all();
     $dec_learnmethods = [];
     foreach ($decleration->learnmethods as $method) {
         $dec_learnmethods[] = $method->id;
     }
     $dec_estimations = [];
     foreach ($decleration->estimations as $estimation) {
         $dec_estimations[$estimation->id] = ['min' => $estimation->pivot->min, 'max' => $estimation->pivot->max];
     }
     $dec_certificaterules = [];
     foreach ($decleration->certificaterules as $certificaterule) {
         $dec_certificaterules[$certificaterule->id] = $certificaterule->pivot->percentage;
     }
     $dec_materials = [];
     foreach ($decleration->learnmaterials as $material) {
         $dec_materials[] = $material->id;
     }
     $editables = $decleration->editables->lists('field_name')->toArray();
     return view('user.edit_user_form', ['decleration' => $decleration, 'fields' => $fields, 'terms' => $terms, 'listener_numbers' => $listener_numbers, 'learn_methods' => $learn_methods, 'dec_learnmethods' => $dec_learnmethods, 'estimations' => $estimations, 'dec_estimations' => $dec_estimations, 'ratingsystems' => $ratingsystems, 'certificaterules' => $certificaterules, 'dec_certificaterules' => $dec_certificaterules, 'learnmaterials' => $learnmaterials, 'dec_materials' => $dec_materials, 'editables' => $editables]);
 }