本文整理汇总了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);
}
示例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;
}
示例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"));
}
示例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());
});
}
示例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'));
}
示例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);
}
示例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'));
}
示例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());
});
}
示例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'));
}
示例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'));
}
示例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
}
示例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'));
}
示例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'));
}
示例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());
});
}