bluetail
bluetail

Reputation: 183

How to display only the column has data in Laravel?

enter image description hereI'm making photo gallery. I have a question.

I would like to display data only 'images' column has data. some of 'images' column has empty

Here is my current code.

public function pic_s1()
    {
        $images = ImageGallery::where('images', "*.jpg")->orderBy(DB::raw('LENGTH(wc), wc'))->limit(20.)->get();
        return view('pic_s1',compact('images'));
    } 

Could you teach me how to write query please?

Upvotes: 0

Views: 148

Answers (2)

Ranjeet
Ranjeet

Reputation: 579

use whereNotNull like this:

public function pic_s1()
    {
        $images = ImageGallery::whereNotNull('image')->where('image', '!=', '')->orderBy(DB::raw('LENGTH(wc), wc'))->limit(20.)->get();
        return view('pic_s1',compact('images'));
    } 

Upvotes: 1

Risheekant Vishwakarma
Risheekant Vishwakarma

Reputation: 1046

You can write query like this

public function pic_s1()
    {
        $images = ImageGallery::whereNotNull('images)->where('images','!=','')->orderBy(DB::raw('LENGTH(wc), wc'))->limit(20.)->get();
        return view('pic_s1',compact('images'));
    } 

Upvotes: 1

Related Questions