/** * Show the form for editing the specified resource. * This function takes an AJAX request and an ID * To edit a project record. * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { //current user $user_id = auth()->user()->id; //project to return with JSON. $returnProject = Project::where('user_id', $user_id)->where('id', $id)->get(); //what informatoin do we need returned to the view from the database records? Column ID's from database. $keys = array('name', 'color'); //sanitize the project for save output $sanitized_project = sanitizeForOutput_H($keys, $returnProject); //return the sanitized object. if ($sanitized_project) { dd($sanitized_project); Response::json($sanitized_project); } else { return false; } }
public function completed(Request $request) { //current user $user_id = auth()->user()->id; $inputs = $request->all(); if (isset($inputs['task_id']) && is_numeric($inputs['task_id'])) { $existingTask = Task::where('user_id', $user_id)->where('id', $inputs['task_id'])->first(); /* * Update the database */ if ($existingTask['original']['completed'] == 0) { Task::where('user_id', $user_id)->where('id', $inputs['task_id'])->update(['completed' => 1]); } elseif ($existingTask['original']['completed'] == 1) { Task::where('user_id', $user_id)->where('id', $inputs['task_id'])->update(['completed' => 0]); } /* * Data to send back */ //if coming from a project page only send project information. if ($inputs['is_project_page'] == 'true') { $returnTasks = filteredTasksToDisplayWithProject_H($request->session()->get('display_tasks'), $request, $inputs['project_id']); } //if coming from view all tasks send all tasks back if ($inputs['is_project_page'] == 'false') { $returnTasks = filteredTasksToDisplayNoProject_H($request->session()->get('display_tasks'), $request); } //what informatoin do we need returned to the view from the database records? Column ID's from database. $keys = array('id', 'project_id', 'due_date', 'priority', 'description', 'completed'); $sanitized_tasks = sanitizeForOutput_H($keys, $returnTasks); //return the sanitized object. return Response::json($sanitized_tasks); } }