当前位置: 首页>>代码示例>>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;未经允许,请勿转载。