public static function replies() { $value = Cache::remember('statistics_replies', 5, function () { return Reply::count(); }); return $value; }
/** * Execute the console command. * * @return mixed */ public function fire() { foreach (Reply::all() as $reply) { if (!$reply->topic) { $reply->delete(); } } }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $user = Auth::user(); $reply = Reply::findOrFail($this->route('id')); $this->reply = $reply; if ($user && ($reply->user_id == $user->id && !$reply->topic->is_blocked || $user->can('manage_posts'))) { return true; } else { return false; } }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if (Auth::check()) { $user = Auth::user(); $reply = Reply::findOrFail($this->route('id')); if ($reply->user_id == $user->id || $user->can('manage_posts')) { return true; } else { return false; } } else { return false; } }
public function markAnswer(AnswerReply $request, $id) { //Pažymim atsakymą. $reply = Reply::findOrFail($id); $reply->is_answer = 1; $reply->user->increment('karma_count', 5); $reply->save(); //Užrakinam temą. $topic = Topic::findOrFail($reply->topic_id); $topic->is_blocked = 1; $topic->is_answered = 1; $topic->save(); flash()->success('Pranešimas pažymėtas kaip atsakymas!'); return redirect()->route('topic.show', [$topic->slug]); }
public function results(Request $request) { $type = $request->input('type'); $query = $request->input('query'); if ($type == 'user') { $results = User::where('username', 'LIKE', '%' . $query . '%')->paginate(20); } elseif ($type == 'reply') { $results = Reply::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20); } elseif ($type == 'topic') { $results = Topic::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20); } elseif ($type == 'status') { $results = Status::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20); } return view('search.results', compact('type', 'query', 'results')); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if (Auth::check()) { //if user owns the topic or if user is admin $reply = Reply::findOrFail($this->route('id')); $topic = $reply->topic; $this->reply = $reply; if ($topic->user_id == Auth::user()->id || Auth::user()->can('manage_topics')) { return true; } else { return false; } } else { return false; } }
public function vote(VoteRequest $request, $vote, $type, $id) { $user = Auth::user(); if ($type == 'tema') { $type = 'Topic'; $_votable = Topic::findOrFail($id); } else { $type = 'Reply'; $_votable = Reply::findOrFail($id); } $_vote = Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->first(); //Ištrinam visus balsus, jei netyčia susibugintų. if ($_vote) { Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->delete(); if ($_vote->is != $vote) { $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]); //cancel old vote and give new vote if ($vote == 'upvote') { event(new UpVoted($_votable, $created_vote, $_votable->user, true)); } else { event(new DownVoted($_votable, $created_vote, $_votable->user, true)); } } else { //cancel current vote if ($vote == 'upvote') { event(new DownVoted($_votable, $_vote, $_votable->user, false)); } else { event(new UpVoted($_votable, $_vote, $_votable->user, false)); } } } else { $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]); //just vote if ($vote == 'upvote') { event(new UpVoted($_votable, $created_vote, $_votable->user, false)); } else { event(new DownVoted($_votable, $created_vote, $_votable->user, false)); } } return response('success', 200); }
/** * Run the migrations. * * @return void */ public function up() { Topic::where('vote_count', '<', '0')->update(['vote_count' => 0]); Reply::where('vote_count', '<', '0')->update(['vote_count' => 0]); }