public function decide($id) { //need to get data froP database $project = Project::find($id); $user = \Auth::user(); $tasks = task::where('project_id', '=', $id)->get(); $count = $tasks->count(); if ($count > 0) { $task = task::where('project_id', '=', $id)->firstOrFail(); if (TaskUser::where('user_id', $user->id)->where('task_id', $task->id)->get()->count() == 0) { $userTask = new TaskUser(); $userTask->user_id = $user->id; $userTask->task_id = $task->id; $userTask->save(); } } return view('project.profile', compact('project', 'tasks', 'count')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $project_id, $id) { $task = DB::table('tasks')->where('id', '=', $id)->first(); $input = $request->all(); $validator = $this->validator($input); if ($validator->fails()) { return redirect('admin/task/' . $project_id . '/' . $task->id . '/edit')->withErrors($validator); } else { $task->taskCode = $request->input('taskCode'); $task->taskName = $request->input('taskName'); $task->taskContent = $request->input('taskContent'); $task->taskStartDate = $request->input('taskStartDate'); $task->taskEndDate = $request->input('taskEndDate'); $task->taskStatus = "0"; DB::table('tasks')->where('id', '=', $id)->update(['taskCode' => $task->taskCode, 'taskName' => $task->taskName, 'taskContent' => $task->taskContent, 'taskStartDate' => $task->taskStartDate, 'taskEndDate' => $task->taskEndDate]); $taskUsers = DB::table('taskUser')->where('task_id', '=', $id)->delete(); $usersTask = $request->input('userTask'); foreach ($usersTask as $userTask) { $taskUser = new TaskUser(); $taskUser->task_id = $task->id; $taskUser->user_id = $userTask; $taskUser->save(); } return redirect('admin/task/' . $project_id . '/' . $task->id)->withErrors('Edited Task Succeed'); } }