Example #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     //$articles=Article::all();
     $articles = Article::latest()->get();
     return $articles;
 }
 public function index()
 {
     //Only get articles of current date or older
     //                   get the latest on top       where  value  is less then current date 'Carbon::now()'.
     // A) $articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
     // B) This way is better, now the scope 'published()'  is called from the 'article' model
     $articles = Article::latest('published_at')->published()->get();
     //Get all articles (array)
     //$articles = Article::all();
     // Get all article objects  and order_by 'published_at' values
     //$articles = Article::latest('published_at')->get();
     //A) In the view 'articles.index', send the articles] objects
     return view('articles.index', compact('articles'));
     //B) or with this:
     //  return view('articles.index')->with('articles', $articles);
 }