I got this error on laravel blade file -ErrorException A non well formed numeric value encountered on helper funtion

31 views Asked by At

Form helper get string value. Then convert numeric value. Other helper functions work properly but only this portion doesn't work.

    if(isset($result[$product->id])){
       $productArray[$product->id]+= @helper::getCtnQty($product->id,$result[$product->id]); // Error get from this line. but when dd I get value in int form
       $singleProductArray[$product->id]  = $productArray[$product->id];              
       <td style="text-align:center;font-weight: 700">
         {{@helper::getCtnQty($product->id,$result[$product->id])}}
       </td>
    }
1

There are 1 answers

0
Anika Tabassum On BEST ANSWER

I needed integer value for code but I get string. And This error usually pops up when we try to add an integer with a string or some type of non numeric field.

So, firstly I check type by gettype(). Then write (int) before helper function.

    if(isset($result[$product->id])){
        $productArray[$product->id]+= (int)@helper::getCtnQty($product->id,$result[$product->id]); 
        $singleProductArray[$product->id]  = $productArray[$product->id];              
     <td style="text-align:center;font-weight: 700">
       {{@helper::getCtnQty($product->id,$result[$product->id])}}
     </td>
    }