Sonu Kumar
Sonu Kumar

Reputation: 969

If Condition not match in php

We have an issue with PHP developing if condition how to match condition

$individualStock = DB::table('inventory')->leftjoin('inventory_detail','inventory_detail.inventory_ref_id','=','inventory.inventory_ref_id')
            ->selectRaw('inventory.*')
            ->whereIn('inventory_detail.attribute_id', [$attributeid])
            ->where(DB::raw('(select count from `inventory_detail` where `inventory_detail`.`attribute_id` in ('.$attributeid.') and `inventory_ref_id`= "'.$inventory->inventory_ref_id.'")'),'=',$count)
            ->where('inventory.inventory_ref_id','=',$inventory->inventory_ref_id)              
            ->groupBy('inventory_detail.inventory_ref_id')
            ->get();    

I match condition with some issue with condition

$individualStack = Collection form sql empty array
$countValue = count($individualStock) // 0


                if(count($individualStock) > 0  ){ // 0 > 0 // FIX condition
              echo "Why here print Hello";die();                
                $inventory_ref_id[] = $individualStock[0]->inventory_ref_id;
                $stockIn += $individualStock[0]->stock;
            } else {
echo "Why"
}

Fix issue $inventory_ref_id[] for all over code in foreach problem has solved

Please help me, How can I do fix this condition?

Upvotes: 0

Views: 482

Answers (3)

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

I think you are getting a collection so the correct method will be

$individualStack ->isEmpty()

or

$individualStack->isNotEmpty()

Upvotes: 0

Hitesh
Hitesh

Reputation: 243

you can use just one function

if($individualStock->isEmpty())

Upvotes: 0

Bram Verstraten
Bram Verstraten

Reputation: 1547

To count the records you should use the count() method.

$countValue = $individualStock->count();

See the Laravel documentation about this.

If you just want to check if the result is empty, use the isEmpty() method instead.

if ($individualStock->isEmpty()) {
    // ....
}

Upvotes: 2

Related Questions