0

I tried to define a local scope in my project to show popular(most downloaded)in my Home Page...so this is my File Model codes:

        public function scopePopular($query)
        {
        return $query->orderBy('file_download_num');
        }

As you know "file_download_num" is the field in database im trying to get data from... so this is how I used this scope in my HomeController:

        $popularFiles = File::Popular()->get();

I didn't use count() method in my Controller or Model!But still getting Error!so any suggestion? notice:php version is 7.3

navid
  • 1
  • 6

1 Answers1

-1

I found that adding a toArray() method in controller can help count() method work correctly...it worker for me...so controller should be like this:

$popularFiles = File::Popular()->get()->toArray();
navid
  • 1
  • 6