public function editTask($idbp, $id) { $bp = BusinessPlan::findOrFail($idbp); $task = Task::findOrFail($id); $actions = Action::lists('description'); $user = User::lists('name'); $groups = Group::lists('name', 'id'); $users = User::lists('name', 'id'); $names = explode(', ', $task->collaborators); $selectedUsers = array(); $selectedGroups = array(); foreach ($names as $name) { if (count(User::all()->where('name', $name)) > 0) { array_push($selectedUsers, User::all()->where('name', $name)->first()->id); } if (count(Group::all()->where('name', $name)) > 0) { array_push($selectedGroups, Group::all()->where('name', $name)->first()->id); } } $progress = ['0' => 'Not Started', '1' => 'In Progress', '2' => 'Done']; return view('businessPlan.editTask', compact('task', 'actions', 'groups', 'user', 'idbp', 'users', 'selectedUsers', 'selectedGroups', 'progress')); }