/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $training = Training::lists('training_name', 'id'); $trainees = User::lists('id', 'name'); //dd($trainees); $newTrainees = array(); $test = ""; foreach ($trainees as $traineesName => $traineeId) { $listOfTraineesInRoleTable = Role_user::whereuser_id($traineeId)->firstOrFail(); if ($listOfTraineesInRoleTable->role_id == 3) { $traineeHas = UserTraining::whereuser_id($traineeId)->first(); if ($traineeHas == true) { $test++; } else { array_push($newTrainees, $traineeId); } } else { continue; } } //print_r($newTrainees); return view('user_traininginfo/create', compact('training', 'trainees', 'newTrainees', 'listOfTraineeInRoleTable')); }