Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freemium's avatar

A non-numeric value encountered

       $popular = Search::orderBy('frequency', 'desc')->pluck('query')->all();

        $popularProduct = Product::with('thumbnail', 'reviews', 'deals')->get();

        foreach ($popular as $key => $value) {
            $popularProduct->where('name', 'like', '%' . $value . '%');
        }
        $popularProduct = $popularProduct->where('status', 1)->shuffle()->take(5);

blade file

                                                        {{ $popularProduct[4]->pricing_scheme->price * Session::get('currentCurrency')->rate }}</span>

appserviceprovider boot method

 $currency = Currency::where('code', 'USD')->first();
        if (!session()->has('currentCurrency')) {
            session()->put('currentCurrency', $currency);
        }

while dd($popular);

array:78 [▼
  0 => "skybag"
  1 => "pant"
  2 => "Shoe"
  3 => "Man's pant"
  4 => "Track Jogger Pants for man"
  5 => "One Piece dress for girl"
  6 => "pants"
  7 => "dress"
  8 => "clothing"
  9 => "carpet"
  10 => "goat"
  11 => "Led tv"
  12 => "tshirt"
  13 => "bil"
  14 => "Fortuna  26MTB 2WD"
  15 => "bike"
  16 => "t-shirt"
  17 => "hwt"
  18 => "sneaker"
  19 => "bag"
  20 => "Old Car"
  21 => "test"
  22 => "track"
  23 => "2wd"
  24 => "car"
  25 => "Printed"
  26 => "Mini tractor"
  27 => "shirt"
  28 => "bicycle"
  29 => "Wireless Earphone"
  30 => "Brass cooker and kitchenwere"
  31 => "Garjoo Taiwan"
  32 => "bed"
  33 => "hotel"
  34 => "Narayan Prasad Dhital"
  35 => "fortuna"
  36 => "ewewer"
  37 => "chair"
  38 => "Annimal"
  39 => "vehicle"
  40 => "Escort"
  41 => "Track Jogger Pants for man"
  42 => "Philips 8.5 W Round B22 LED Bulb"
  43 => "Authentic Printed Tee"
  44 => "old durbar"
  45 => "david"
  46 => "Tractor"
  47 => "buffalo"
  48 => "baby product"
  49 => "robot"
  50 => "Bluetooth Speaker"
  51 => "Khujati"
  52 => "wireless"
  53 => "Crystal Furnitech Sigma Engineered Wood Coffee Table"
  54 => "Dabur Chyawanprash 500 Gm"
  55 => "Jhummar"
  56 => "t"
  57 => "FOOTWEAR"
  58 => "tshi"
  59 => "nara"
  60 => "Carpt"
  61 => "Basketball Sneaker"
  62 => "gf"
  63 => "pan"
  64 => "garjoo"
  65 => "shoesn"
  66 => "dhital"
  67 => "sho"
  68 => "conv"
  69 => "furn"
  70 => "carp"
  71 => "plastic peni"
  72 => "you make"
  73 => "jogg"
  74 => "wine"
  75 => "head"
  76 => "Printed t-shirt"
  77 => "333"
]

while dd($popularProduct)

Illuminate\Database\Eloquent\Collection {#2062 ▼
  #items: array:5 [▶]
  #escapeWhenCastingToString: false
}

how can i resolve this

0 likes
12 replies
freemium's avatar

@Sinnbeck

                                                        {{ $popularProduct[4]->pricing_scheme->price * Session::get('currentCurrency')->rate }}</span>

http://test.garjoo.com/en when we hit this url multiple time then that error throws ...you can try hitting that same url multipletime

Sinnbeck's avatar

Or dd both and post result

@dd($popularProduct[4]->pricing_scheme->price, Session::get('currentCurrency')->rate)
SilenceBringer's avatar

@freemium I think sometimes

$popularProduct[x]->pricing_scheme->price

returns string, which throws an error

Check the price, may it contains string value? Or has accessor? Or Cast?

freemium's avatar

@SilenceBringer when i @dd(session()->get('currentCurrency')) in blade file i get this one

   "id" => 1
    "rate" => 1.0
    "symbol" => "$"
    "code" => "USD"
    "created_at" => "2021-01-27 01:38:50"
    "updated_at" => "2021-01-27 01:38:50"
SilenceBringer's avatar
Level 55

@freemium if you hit your url seeveral times you'll see that it shows different id of popular product. which means for one of product you have wrong value

can you check the price of all pricing schemas manually in database?

Sinnbeck's avatar

@freemium One way to try and debug it would be to add a conditional dd. Add it before the code that fails!

@if (!is_numeric($popularProduct[4]->pricing_scheme->price) || !is_numeric(Session::get('currentCurrency')->rate)
    @dd($popularProduct[4]->pricing_scheme->price, Session::get('currentCurrency')->rate)

@endif

Please or to participate in this conversation.