Argument 1 missing for Illuminate \ Support \ Collection :: get ()

I have simple Laravel 5.1 code and I get ErrorException Missing argument 1 for Illuminate\Support\Collection::get(). Here is the code:

public function boot()
  {
     $news = News::all()->take(5)->get();
     view()->share('sideNews', $news);

  }

Whenever I delete ->get();, it works. This is my first time using eloquent. I remember when I use the query builder, I always add ->get()to the last line of code. Am I doing it right? Thanks.

+4
source share
1 answer

Do not use the method all:

public function boot()
{
    $news = News::take(5)->get();

    view()->share('sideNews', $news);
} 
+9
source

Source: https://habr.com/ru/post/1605656/


All Articles