コード例 #1
1
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if (\Auth::check() == false) {
         return redirect('/auth/login');
     }
     // 一页多少文章
     $pageNum = 8;
     $userInfo = \Auth::user();
     $data = array();
     $data['articles'] = \App\Article::latest()->get();
     $data['userInfo'] = $userInfo;
     $dataArticles = array();
     $cacheKey = 'laravel:articles:index';
     $redis = new \Predis\Client(array('host' => '127.0.0.1', 'port' => 6379));
     $dataArticles = $redis->get($cacheKey);
     if (!$dataArticles || true) {
         //$dataArticles = \App\Article::latest()->take($pageNum)->with('content')->get()->toArray();
         $dataArticles = \App\Article::latest()->with('content')->paginate($pageNum)->toArray();
         //             var_dump($dataArticles);exit();
         $redis->setex($cacheKey, 3600 * 12, serialize($dataArticles));
     } else {
         $dataArticles = unserialize($dataArticles);
     }
     $data['articles'] = $dataArticles;
     //var_dump($data);exit();
     // $articleArr[0]['relations']['content']['content']
     return view('articles.admin.articleList')->with('data', $data);
 }
コード例 #2
0
ファイル: FunctionController.php プロジェクト: 2zH/wind.moe
 public function feed()
 {
     $items = "";
     $articles = Article::latest('created_at')->published()->get();
     //->take(10)
     foreach ($articles as $article) {
         //            $str = explode('__more__',$article['text']);
         //            $article['text']=(string)$str[0];
         //To rss item data
         $title = "<title><![CDATA[" . $article['title'] . "]]></title>";
         $description = "<description><![CDATA[" . $article['text'] . "]]></description>";
         $author = "<author><![CDATA[" . $article['author'] . "]]></author>";
         $pubDate = "<pubDate>" . date('D M d Y H:i:s', strtotime($article['created_at'])) . " GMT+0800" . "</pubDate>";
         $link = "<link>https://wind.moe/article/" . $article['id'] . "</link>";
         $guid = "<link>https://wind.moe/article/" . $article['id'] . "</link>";
         $category = "<category domain='https://wind.moe/articles/{$article['category']}'><![CDATA[" . $article['category'] . "]]></category>";
         $items .= "<item>" . "{$title}" . "{$description}" . "{$author}" . "{$pubDate}" . "{$link}" . "{$guid}" . "{$category}" . "</item>";
     }
     $web_title = "<title>" . "<![CDATA[ WindCore ]]>" . "</title>";
     $web_link = "<link>" . "https://wind.moe" . "</link>";
     $web_description = "<description>" . "<![CDATA[WindCore 是稗田千秋的一个个人博客,记录个人的点点滴滴,包含随笔,代码,日常,ACGN等内容. ]]>" . "</description>";
     $channel = "{$web_title}" . "{$web_link}" . "{$web_description}" . "{$items}";
     $rss = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" . "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" . "<channel>" . "{$channel}" . "</channel>" . "</rss>";
     return \Response::make($rss, 200, ['Content-Type' => 'text/xml']);
     //		return response($articles,200);//->header('Content-Type','text/xml')
     //		return $articles;
 }
コード例 #3
0
 public function index()
 {
     //$articles = Article::all();
     $articles = Article::latest("published_at")->published()->get();
     //latest(field) orders results in desc order; "published" is a custom scope for Article model
     return view("articles.index", compact("articles"));
 }
コード例 #4
0
 /**
  * Compose the navigation bar
  */
 private function composeNavigation()
 {
     //		view()->composer('partials.nav', 'App\Http\Composers\NavigationComposer');
     view()->composer('partials.nav', function ($view) {
         $view->with('latest', Article::latest()->first());
     });
 }
コード例 #5
0
 public function index()
 {
     //return \Auth::user()->username;
     $articles = Article::latest('published_at')->published()->get();
     //$latest = Article::latest()->first(); // We do not want to copy and paste it to every function. We put it to AppServiceProvider.
     return view('articles.index', compact('articles', 'latest'));
 }
コード例 #6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$a = new ArticleRepository(new \App\Article);
     //var_dump($a->getLatestArticles());exit();
     // 一页多少文章
     $pageNum = 10;
     $userInfo = \Auth::user();
     $data = array();
     $data['articles'] = Article::latest()->published()->get();
     $data['userInfo'] = $userInfo;
     $dataArticles = array();
     $curPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $cacheKey = 'laravel:articles:index:page:' . $curPage;
     $redis = new \Predis\Client(array('host' => '127.0.0.1', 'port' => 6379));
     $dataArticles = $redis->get($cacheKey);
     if (!$dataArticles) {
         //$dataArticles = \App\Article::latest()->take($pageNum)->with('content')->get()->toArray();
         $dataArticles = App\Article::latest()->with('content')->paginate($pageNum)->toArray();
         //var_dump($dataArticles);exit();
         $redis->setex($cacheKey, 3600 * 12, serialize($dataArticles));
     } else {
         $dataArticles = unserialize($dataArticles);
     }
     $data['articles'] = $dataArticles;
     //var_dump($data);exit();
     // $articleArr[0]['relations']['content']['content']
     return view('articles.index')->with('data', $data);
 }
コード例 #7
0
 public function index()
 {
     //  $articles = Article::latest('published_at')->unpublished()->get();
     $articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
     //$articles = Article::latest('published_at')->get();
     return view('articles.index', compact('articles'));
 }
コード例 #8
0
 private function composeNavigation()
 {
     //view()->composer('partials.nav', 'App\Http\Composers\NavigationComposer@compose'); // Makes object of "NavigationComposer" and calls "compose" method on it
     view()->composer('partials.nav', function ($view) {
         $view->with('latest', Article::latest()->first());
     });
 }
コード例 #9
0
 public function index()
 {
     // $articles = Article::all();
     $articles = Article::latest('published_at')->published()->get();
     // return view('articles.index')->with('articles', $articles);
     return view('articles.index', compact('articles'));
 }
コード例 #10
0
 public function index()
 {
     //displaying only the current articles, not the ones that have a future date
     $articles = Article::latest('published_at')->published()->get();
     $latest = Article::latest()->first();
     return view('articles.index', compact('articles', 'latest'));
 }
コード例 #11
0
ファイル: Controller.php プロジェクト: AdrianKuriata/projekt
 public function index()
 {
     $articles = Cache::remember('articles', 15, function () {
         return Article::latest('created_at')->take(12)->get();
     });
     return view('main', compact('articless', 'articles'));
 }
コード例 #12
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //Recuperar todos los articulos
     $articles = Article::latest('published_at')->unpublished()->get();
     return view('articles.index', compact('articles'));
     //compact hace un arreglo
 }
コード例 #13
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $admin = User::first();
     $tags = Tag::all();
     $articles = Article::latest()->published()->get();
     return view($this->theme() . 'home', compact('articles', 'admin', 'tags'));
 }
コード例 #14
0
 public function home()
 {
     $articles = Article::latest()->get();
     $opportunities = Opportunity::all()->sort();
     //        return view('articles.index', compact('articles'));
     return view('pages.home', compact('articles', 'opportunities'));
 }
 /**
  *
  */
 private function composeNavigation()
 {
     $var = array();
     view()->composer('partials.nav', function ($view) {
         $view->with('latest', Article::latest()->first());
     });
 }
コード例 #16
0
 public function index()
 {
     // $articles = Article::all();
     // return \Auth::user()->name;
     $articles = Article::latest('published_at')->published()->get();
     return view('articles.index', compact('articles'));
 }
コード例 #17
0
 /**
  * Compose the navigation
  */
 private function composeNavigation()
 {
     view()->composer('partials.nav', function ($view) {
         $article = Article::latest();
         $view->with('latest', $article->exists() ? $article->first() : new Article());
     });
 }
コード例 #18
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$articles = Article::all();
     //Get by symbol search Ctrl+Alt+shift+N
     $articles = Article::latest('published_at')->get();
     return view('articles.index', compact('articles'));
 }
コード例 #19
0
ファイル: HomeController.php プロジェクト: museuvirtual/atlas
 public function home()
 {
     $lastRecords = MammalRecord::where('numPics', '>', 0)->where('accepted', TRUE)->orderBy('updated_at', 'desc')->take(4)->get();
     $fixedArticles = Article::latest('date_to_publish')->where('approved', true)->where('fixed_position', '>', 0)->where('date_to_publish', '<=', Carbon::now())->get();
     $lastArticles = Article::latest('date_to_publish')->where('approved', true)->where('date_to_publish', '<=', Carbon::now())->get();
     return view('home4', compact('lastRecords', 'lastArticles', 'fixedArticles'));
 }
コード例 #20
0
ファイル: PagesController.php プロジェクト: kobeuu/bpb-sf
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $sliders = Slider::latest()->get();
     $images = Image::latest()->take(4)->get();
     $news = News::latest('published_at')->published()->take(3)->get();
     $articles = Article::latest('published_at')->published()->take(3)->get();
     return view('pages.index', compact('articles', 'news', 'images', 'sliders'));
 }
コード例 #21
0
 /**
  * Function for the blog homepage, displaing all published posts.
  */
 public function index()
 {
     $pagecode = '5meuVGy2zOKvjsZO';
     $meta = Meta::where('code', $pagecode)->firstOrFail();
     // Get latest published articles, sorted by date & select only given fields.
     $articles = Article::latest('published')->published()->listing()->paginate(4);
     return view('core.article.index', compact('articles', 'meta'));
 }
コード例 #22
0
 public function index()
 {
     if (\Auth::user()) {
         $user = \Auth::user();
     }
     $articles = Article::latest()->published()->paginate(5);
     return view('articles.index', compact('articles'));
 }
コード例 #23
0
 public function index()
 {
     $articles = Article::latest('published_at')->published()->get();
     //$artcls = Article::find(4)->user;
     // dd($artcls);
     //return $articles;
     return view('articles.index', compact('articles'));
 }
コード例 #24
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $articles = Article::latest()->get();
     if ($request->ajax() || $request->wantsJson()) {
         return new JsonResponse($articles);
     }
     return view('articles.index', compact('articles'));
 }
コード例 #25
0
 public function index()
 {
     //    return \Auth::user()->name;
     //without using function
     //$articles=Article::latest('published_at')->where('published_at','<=',Carbon::now())->get();
     $articles = Article::latest('published_at')->published()->get();
     return view('articles.index', compact('articles'));
 }
コード例 #26
0
 public function index()
 {
     //$articles = Article::latest()->get();
     //$articles = Article::latest('wrote_on')->where('wrote_on', '<=', Carbon::now())->get(); passato al Model
     $articles = Article::latest('wrote_on')->withWroteOnDateLowerThanNow()->get();
     //$articles = Article::latest('wrote_on')->withWroteOnDateGreatherThanNow()->get();
     return view('articles.index', compact('articles'));
 }
コード例 #27
0
 public function index()
 {
     #return \Auth::user()->name;
     $articles = Article::latest('published_at')->published()->get();
     return View('articles.index', compact('articles'));
     //same as
     //return View('articles@index')->with('articles',$articles);
 }
コード例 #28
0
 public function index()
 {
     //$articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get(); //order by column desc
     //with scope
     $articles = Article::latest('published_at')->published()->get();
     //return $articles; //to just return JSON as an API, wooooo! APIs!!!!!
     return view('articles.index', compact('articles'));
 }
コード例 #29
0
 public function index()
 {
     if (Request::has('filterBycategory_id')) {
         $articles = Article::where('category_id', Request::input('filterBycategory_id'))->get();
     } else {
         $articles = Article::latest()->get();
     }
     return view('articles.index', compact('articles'));
 }
コード例 #30
0
 public function index()
 {
     $articles = Article::latest('published_at')->get();
     $authors = [];
     foreach ($articles as $article) {
         $authors[] = User::findOrFail($article->user_id)->toArray()['name'];
     }
     return view('articles.index', ['articles' => $articles, 'authors' => $authors]);
 }