/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Contact $contact, Request $request, $id) { // $note = Note::find($id); $note->update($request->except('note_date')); $note->note_date = Carbon::parse($request->input('note_date')); $note->save(); return redirect()->route('contacts.show', ['id' => $contact->id]); }
public function deleteNote(Request $request) { $noteid = $request['noteid']; $note = Note::find($noteid); $user = Auth::user(); if ($note->user_id == $user->id) { $note->delete(); return 1; } }
/** * Remove the specified resource from storage. * @return Response */ public function delete() { $validator = Validator::make(Input::all(), array('id' => 'required|integer', 'api_key' => 'required')); if ($validator->fails()) { return response()->json(array('errors' => $validator->errors())); } $this->_isOwner(); $note = Note::find(Input::get('id')); if ($note) { $deleted = $note->delete(); if ($deleted) { return response()->json(array('status' => 'successful')); } } return repsonse()->json(array('status' => 'failed')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { //return $request->get('note_id'); $note = Note::find($request->get('note_id')); if (count($note) > 0) { $note->past = 1; $note->save(); } $stripped_note = str_replace("'", ''', $request->get('note')); $new_note = new Note(); $new_note->user_id = $request->get('user_id'); $new_note->note = $stripped_note; $new_note->device_id = $request->get('device_id'); $new_note->past = 0; $new_note->save(); return redirect()->back(); }
public function handleAction(Request $request) { $action = $request->input('_action'); if ($action == 'addNote') { $param = ''; if ($request['private'] == 'yes') { $param = 'PRIVATE'; } else { $param = 'PUBLIC'; } $note = Note::create($request->all()); $note->scope = $param; $note->save(); return response(['status' => 'success']); } else { if ($action == "deleteNote") { $note = Note::find($request->input('id')); $note->delete(); return response(['status' => 'success']); } else { return response(['status' => 'error']); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $note = Note::find($id); if (Auth::User()->id != $note->user_id) { Flash::warning('You are not authorized to do that'); return redirect()->route('home'); } $note->delete(); Flash::info('Note deleted!'); return redirect()->route('notes.index'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $note = Note::find($id); if (Gate::denies('delete-note', $note)) { abort(403); } $exec = $note->delete(); if ($exec) { return response()->json(["status" => "success"]); } }
/** * Unlinks two previously linked notes * * @param int $id1 First note id * @param int $id2 Second note id * * @return Response A JSON encoded message containing the result */ public function getUnlinkNotes($id1, $id2) { if ($id1 <= 0 || $id2 <= 0) { return response()->json(['message', 'Bad request: An ID was invalid'], 400); } try { Note::findOrFail($id1); Note::findOrFail($id2); } catch (ModelNotFoundException $e) { return response()->json(['message', 'Some ID did not belong to any note'], 404); } // This note is the currently active note $note = Note::find($id1); $note2 = Note::find($id2); // And it should be detached to this ID (and vice versa) $note->notes()->detach($id2); $note2->notes()->detach($id1); return response()->json(['message', 'Notes linked successfully'], 200); }
/** * Updates a specific note * * This function uses an Eloquent query to update content, deadline and * completed for a specific note. * * @since 1.1.0 * * @param int $noteID The ID of the note to be updated * @return int The HTTP status code */ public function updateNote($notedata) { try { $statusCode = 200; $note = Note::find($notedata->id); $note->content = $notedata->content; $note->time_deadline = $notedata->deadline; if ($notedata->completed == "true") { $note->completed = 1; } else { $note->completed = 0; } $note->save(); } catch (Exception $e) { $statusCode = 400; } finally { return $statusCode; } }
/** * Searches the notes for possible trails and displays them * * @return Illuminate\Http\Response */ public function index() { $notes = Note::all(['id']); // Trails collection $res = new Collection(); foreach ($notes as $note) { if (count($note->next()) > 0) { $res[] = $this->getTrails($note, true); } } // Eager preload all titles for the notes we have in our trails $noteTitles = []; foreach ($res as $notesWithTrails) { foreach ($notesWithTrails as $trailsWithNotes) { foreach ($trailsWithNotes as $note) { $tmp = Note::find($note); $noteTitles[$note] = $tmp->title; } } } return view('trails.list', ["trailContainer" => $res, "noteTitles" => $noteTitles]); }
/** * Validate AND Save/Crate a new Note. * * @param Request $request * @return Response */ public function store(Request $request) { $page = $request->session()->get('page'); if ($request->save_edit_hidden == "save_edit_rename_filename") { $rename_id = $request->rename_file_id; $filename = $request->rename_file; $input = array('original_filename' => $filename); $entry = Fileentry::find($rename_id); $entry->fill($input)->save(); $request->session()->flash('alert-success', 'File was successful renamed!'); return redirect('/note/' . $request->note_id . '/update?page=' . $page . '&filetab=1'); } $this->validate($request, ['title' => 'required|max:255']); //check if tags belong all to the category_id foreach (explode(",", $request->tags) as $temp) { $t = Tag::find($temp); if ($t) { if ($t->category_id != $request->category) { return Redirect::back()->withErrors('Tag ' . $t->name . ' is from the wrong category!')->withInput(); } } } $input = array('title' => $request->title, 'description' => $request->description, 'category_id' => $request->category, 'tag_ids' => ',' . $request->tags . ','); if ($request->note_id) { $note = Note::find($request->note_id); $note->fill($input)->save(); $request->session()->flash('alert-success', 'Note was successful updated!'); } else { $note = new Note(); $note = $note->create($input); $request->session()->flash('alert-success', 'Note was successful added!'); } if ($request->save_edit or $request->save_edit_hidden) { return redirect('/note/' . $note->id . '/update?page=' . $page . "&filetab=" . $request->filetab); } else { return redirect('/notes?page=' . $page); } }
/** * Updates a note * * @param Request $request * @param integer $id note id * * @return Response */ public function postEdit(Request $request, $id) { // Update a note $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'content' => 'required|min:3']); if ($validator->fails()) { return redirect('/notes/edit/' . $id)->withErrors($validator)->withInput(); } // Get the note $note = Note::find($id); // First add any potential new tags to the database. // And also attach them if not done yet if (count($request->tags) > 0) { $tagIDs = []; foreach ($request->tags as $tagname) { $tag = Tag::firstOrCreate(["name" => $tagname]); $tagIDs[] = $tag->id; } // Sync tag list $note->tags()->sync($tagIDs); } else { // Sync with empty array to remove all $note->tags()->sync([]); } if (count($request->references) > 0) { // Same for references $referenceIDs = []; foreach ($request->references as $referenceId) { try { $ref = Reference::findOrFail($referenceId); // If this line is executed the model exists $referenceIDs[] = $ref->id; } catch (ModelNotFoundException $e) { // Do nothing } } $note->references()->sync($referenceIDs); } else { // Sync with empty array to remove all $note->references()->sync([]); } // Update the remaining fields $note->title = $request->title; $note->content = $request->content; $note->save(); // Now redirect to note create as the user // definitely wants to add another note. return redirect(url('/notes/show/' . $id)); }
public function destroy($id) { $note = Note::find($id); $note->delete(); return Response::json('Note Deleted', 200); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $auth = Auth::user(); if (!($note = Note::find($id))) { return Response()->json(['error' => 'No post found'], 200); } if ($auth->id !== $note->user_id) { return Response()->json(['error' => 'Not authorized'], 402); } if (!$note->delete()) { return Response()->json(['error' => 'Error while attempting to delete your F*****G note.'], 500); } return Response()->json(['success' => 'Deleted successfully ..'], 200); }