0
$dp=DB::table('vazhipads')
                ->select('dinaparidhi')
                ->distinct()
                ->where('vazhipad','=',$request->vazhipad)
                ->get();

this is my query

after dd($dp) i got this result

Illuminate\Support\Collection {#1282
  #items: array:1 [
    0 => {#1275
      +"dinaparidhi": 0
    }
  ]
}

i want to check dinaparidhi is >0

i tried like this

if($dp->dinaparidhi > 0)
{

}

but i got some errors

please tell me how to check dinaparidhi>0

3
  • What do you mean by "some errors"? As far as I see, $dp is a collection of entities Commented Jun 24, 2021 at 10:46
  • i got error like this {message: "Property [dinaparidhi] does not exist on this collection instance.", exception: "Exception",…} exception: "Exception" file: "F:\\Devi\\Backend\\devi\\vendor\\laravel\\framework\\src\\Illuminate\\Collections\\Traits\\EnumeratesValues.php" line: 905 message: "Property [dinaparidhi] does not exist on this collection instance." trace: [,…] Commented Jun 24, 2021 at 11:32
  • Yeah: "on this collection instance" is the important information Commented Jun 24, 2021 at 11:34

1 Answer 1

2

if you are sure that you're request return one row, put "first()" instead "get()"; and your condition will work well; if not, you need to do a foreach

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I got the correct result when added first instead of get

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.