0

I want to get my data from database where one of my attribute was empty string instead of null....but my code return all data where NULL and empty string combined...here is my code

public function findAllPersons2(){
        return $this->where('pi_person_type','3')
                     ->where('pi_vendor_id','!=' , '')
                    ->orderBy('pi_name', 'asc')
                    ->get();
    }

3 Answers 3

1

Your code are using an not equal to an empty string condition. To retrieve all persons where pi_vendor_id's is empty, do the following where condition.

->where('pi_vendor_id', '=', '')
Sign up to request clarification or add additional context in comments.

3 Comments

Hi...i already try but more worse it does not return anything of my data
Have you tried removing where('pi_person_type','3') to see if it returns data then? and are you sure that the field is actually empty?
my bad sir i call wrong attribute actually ...thanks for your time
1

Try as below.

$this->where('pi_person_type','3')
                     ->where(function($q){
                         $q->whereNull('pi_vendor_id')->orwhere('pi_vendor_id','');
                     })

                    ->orderBy('pi_name', 'asc')
                    ->get();

Comments

1

This code will also work:

->where('pi_vendor_id', '')

For convenience, if you want to verify that a column is equal to a given value, you may pass the value directly as the second argument to the where method.

https://laravel.com/docs/6.x/queries#where-clauses

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.