當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Article::latest方法代碼示例

本文整理匯總了PHP中app\Article::latest方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::latest方法的具體用法?PHP Article::latest怎麽用?PHP Article::latest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Article的用法示例。


在下文中一共展示了Article::latest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  * 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);
 }
開發者ID:suhanyujie,項目名稱:digitalOceanVps,代碼行數:33,代碼來源:AdminController.php

示例2: feed

 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;
 }
開發者ID:2zH,項目名稱:wind.moe,代碼行數:27,代碼來源:FunctionController.php

示例3: index

 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"));
 }
開發者ID:Aetheus,項目名稱:tutorials-and-exercises,代碼行數:7,代碼來源:ArticlesController.php

示例4: composeNavigation

 /**
  * 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());
     });
 }
開發者ID:kvjnf,項目名稱:laravel_fundamental,代碼行數:10,代碼來源:ViewComposerServiceProvider.php

示例5: index

 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'));
 }
開發者ID:smartedge,項目名稱:Laravel,代碼行數:7,代碼來源:ArticlesController.php

示例6: index

 /**
  * 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);
 }
開發者ID:suhanyujie,項目名稱:digitalOceanVps,代碼行數:33,代碼來源:ArticlesController.php

示例7: index

 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'));
 }
開發者ID:armandolazarte,項目名稱:php_notes,代碼行數:7,代碼來源:ArticlesController.php

示例8: composeNavigation

 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());
     });
 }
開發者ID:fahad-farrukh,項目名稱:laravel,代碼行數:7,代碼來源:ViewComposerServiceProvider.php

示例9: index

 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'));
 }
開發者ID:pranayaryal,項目名稱:laravelblog,代碼行數:7,代碼來源:ArticlesController.php

示例10: index

 public function index()
 {
     $articles = Cache::remember('articles', 15, function () {
         return Article::latest('created_at')->take(12)->get();
     });
     return view('main', compact('articless', 'articles'));
 }
開發者ID:AdrianKuriata,項目名稱:projekt,代碼行數:7,代碼來源:Controller.php

示例11: index

 /**
  * 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
 }
開發者ID:albertorv,項目名稱:Cyber_Rockola,代碼行數:12,代碼來源:ArticlesController.php

示例12: index

 /**
  * 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'));
 }
開發者ID:realnerdo,項目名稱:portfolio,代碼行數:12,代碼來源:ThemeController.php

示例13: home

 public function home()
 {
     $articles = Article::latest()->get();
     $opportunities = Opportunity::all()->sort();
     //        return view('articles.index', compact('articles'));
     return view('pages.home', compact('articles', 'opportunities'));
 }
開發者ID:jubaedprince,項目名稱:incuba_php,代碼行數:7,代碼來源:PagesController.php

示例14: composeNavigation

 /**
  *
  */
 private function composeNavigation()
 {
     $var = array();
     view()->composer('partials.nav', function ($view) {
         $view->with('latest', Article::latest()->first());
     });
 }
開發者ID:piyushpk89,項目名稱:MasteringLaravelCode_by_Christopher_John,代碼行數:10,代碼來源:ViewComposerServiceProvider.php

示例15: composeNavigation

 /**
  * Compose the navigation
  */
 private function composeNavigation()
 {
     view()->composer('partials.nav', function ($view) {
         $article = Article::latest();
         $view->with('latest', $article->exists() ? $article->first() : new Article());
     });
 }
開發者ID:redshot,項目名稱:learning-laravel-5,代碼行數:10,代碼來源:ViewComposerServiceProvider.php


注:本文中的app\Article::latest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。