예제 #1
0
 public function index()
 {
     $user = \Auth::user();
     $time = $this->formatDate();
     $action = 'home';
     $r = Signin::where('user_id', \Auth::user()->id)->first();
     $count = 0;
     $signined = false;
     if ($r) {
         $count = $r['count'];
         if (substr(Carbon::now(), 0, 10) == substr($r['last_signin'], 0, 10)) {
             $signined = true;
         }
     }
     $signinList = Signin::where('last_signin', 'like', substr(Carbon::now(), 0, 10) . '%')->orderBy('last_signin', 'desc')->get();
     foreach ($signinList as &$item) {
         $item['last_signin'] = substr($item['last_signin'], 11, 8);
     }
     $cates = Cate::orderBy('count', 'desc')->limit(6)->get();
     $authors = User::orderBy('score', 'desc')->limit(6)->get();
     $teams = Team::limit(3)->get();
     $recommendedArticles = Article::orderBy('recommend', 'deac')->limit(4)->get();
     $phpArticles = Article::where('cate_id', 1)->limit(5)->get();
     $todayHotArticles = Article::where('published_at', '>=', Carbon::now()->subDay(1))->where('published_at', '<=', Carbon::now())->orderBy('view', 'deac')->limit(6)->get();
     $weekHotArticles = Article::where('published_at', '>=', Carbon::now()->subDay(7))->where('published_at', '<=', Carbon::now())->orderBy('view', 'deac')->limit(6)->get();
     return view('home', compact('user', 'time', 'action', 'signin', 'minus', 'count', 'signined', 'signinList', 'cates', 'authors', 'teams', 'recommendedArticles', 'phpArticles', 'todayHotArticles', 'weekHotArticles'));
 }