bluetail
bluetail

Reputation: 183

How to count laravel search result?

I would like to add this result's total numbers.

Here is my query. It worked fine just display images.

Could you teach me how to write query and blade file please ?

   public function allimg()
    {        
        $images = ImageGallery::whereNotNull('image')->where('image', '!=', '')->limit(200.)->orderBy('id', 'desc')->get();
        return view('allimg',compact('images'));
        
    }

Upvotes: 0

Views: 329

Answers (3)

koko_dump
koko_dump

Reputation: 35

As per Laravel Documentation under queries (See link: https://laravel.com/docs/4.2/queries)

You can use Aggregate Methods such as: count, max, min, avg and sum.

So in your case, you can use count()

Upvotes: 1

auser101
auser101

Reputation: 21

->count()

You can chain this method to get the count from a model.

Upvotes: 1

Andy Song
Andy Song

Reputation: 4684

In your blade.php this will give you the total number of images.

{{$images->count()}}

Upvotes: 4

Related Questions