/** * Execute the console command. * 该任务具体的执行代码, 这边实现定时发邮件 * * @return mixed */ public function handle() { $issue = Issue::published()->latest('issue')->pluck('issue'); $issueArticles = Issue::published()->latest()->first()->articles->groupBy('category_id'); $recommendId = Category::recommend()->pluck('id'); $otherId = Category::other()->pluck('id'); $recommArticles = []; $normalArticles = collect(); // 创建一个新集合 $otherArticles = []; foreach ($issueArticles as $key => $value) { if ($key == $recommendId) { // 推荐分类文章 $recommArticles = $value; } elseif ($key == $otherId) { // 其他分类文章 $otherArticles = $value; } else { $normalArticles = $normalArticles->merge($value); } } // 把推荐分类文章放在集合第一个 其他分类文章放在集合最后一个 $articles = collect(); $articles = $articles->merge($recommArticles)->merge($normalArticles)->merge($otherArticles)->groupBy('category_id'); $users = Subscribe::where('is_confirmed', 1)->get(); foreach ($users as $user) { $this->dispatch(new SendIssueEmail($user, $issue, $articles)); // 推送到队列 } }
public function show($id){ try{ $s = ''; $question = Question::findOrFail($id); if(empty($this->user) or $question->user_id != $this->user->id){ \DB::table('yiiquestions')->increment('views');//счетчик просмотров }else{ $s = Subscribe::where('question_id', '=', $question->id)->where('user_id', '=', $this->user->id)->get(); } return view('questions.show',[ 'question' => $question, 's' => $s, 'answers' => Answer::where('question_id','=',$question->id)->with('user')->get() ]); }catch(ModelNotFoundException $e){ return view('errors.404'); } }