public function visible_bookmarks_count() { $this_tag_name = $this->name; $bookmarks = new Collection(); $all_bookmarks = Bookmark::where('user_id', '=', Auth::user()->id)->orWhere('private', '=', false)->get(); //iterate through all of the potential bookmarks foreach ($all_bookmarks as $bookmark) { $tags = $bookmark->tags()->get(); foreach ($tags as $tag) { if ($tag->name == $this_tag_name) { //user is allowed to see this one so add to collection $bookmarks->push($bookmark); break; } } } //done return $bookmarks->unique('id')->count(); }
public function deleteBookmark(Request $request) { //grab the desired bookmark $bookmark_to_delete = Bookmark::where('user_id', '=', Auth::user()->id)->find($request->bm_id); //for response message $message = array(); //if this user does not own the bookmark, fail and return if (!count($bookmark_to_delete)) { $message = array('status' => 'Error', 'message' => 'That bookmark cannot be removed! You are not the owner!'); //user owns the bookmark, so lets proceed and delete it } else { $bookmark_to_delete->delete(); $message = array('status' => 'OK', 'message' => 'Bookmark with name: ' . $bookmark_to_delete->name . ' removed!'); } //redirect to the dashboard view with the message return redirect('dashboard')->with('message', $message); }