/** * Execute the job. */ public function handle() { $this->topic->body_original = trim($this->topic->body); $this->topic->body = app('markdown')->text($this->topic->body_original); $this->topic->excerpt = $this->excerpt($this->topic->body_original); $this->topic->save(); return $this->topic; }
/** * Execute the job. */ public function handle() { $this->topic->title = Purifier::clean($this->topic->title, 'title'); $this->topic->body_original = Purifier::clean(trim($this->topic->body), 'body'); $this->topic->body = app('markdown')->text($this->topic->body_original); $this->topic->excerpt = $this->excerpt($this->topic->body_original); $this->topic->save(); return $this->topic; }
/** * Run the database seeds. */ public function run() { $replies = factory(PHPHub\Reply::class)->times(1000)->make(); $user_ids = User::lists('id')->toArray(); $topic_ids = Topic::lists('id')->toArray(); foreach ($replies as $reply) { $reply->user_id = array_rand($user_ids, 1); $reply->topic_id = array_rand($topic_ids, 1); $reply->save(); } }
/** * 取消关注帖子. * * @param $topic_id * @param $user_id */ public function unAttention($topic_id, $user_id) { $topic = new Topic(); $topic->id = $topic_id; $topic->attentionBy()->detach($user_id); }
/** * 反对帖子. * * @param Topic $topic * * @return bool */ public function voteDown(Topic $topic) { if ($this->isDownVoted($topic->id, Auth::id())) { $this->resetVote($topic->id, Auth::id()); $topic->increment('vote_count', 1); return false; } $vote_count = 0; if ($this->isUpVoted($topic->id, Auth::id())) { $this->resetVote($topic->id, Auth::id()); $vote_count = 1; } $topic->votes()->create(['is' => 'downvote', 'user_id' => Auth::id()]); $topic->decrement('vote_count', $vote_count + 1); return true; }