title: Laravel Trying to Get property of non object (from eloquent model)
body: <p>Already read some of questions about this problem on stackoverflow and none of that answers apply to me.
  When I run: </p>
  
  <pre><code>$item_price = ItemPrice::where('item_name',$itemname)-&gt;first();
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>$item_price-&gt;price
  </code></pre>
  
  <p>I get <strong>Trying to get property of non-object</strong> but when I run:</p>
  
  <pre><code>dd($item_price = ItemPrice::where('item_name',$itemname)-&gt;first());
  </code></pre>
  
  <p>It's returning object with attributes  name, price etc. I don't really understand what is happening here. </p>
  
  <p>Full code: </p>
  
  <pre><code>foreach ($inventorydecoded-&gt;assets as $asset) {
  
      $i = 0;
      $a = 0;
      while ($a &lt; 1) {
  
        if ($inventorydecoded-&gt;descriptions[$i]-&gt;classid == $asset-&gt;classid) {
          $a = 1;
          $classid = $inventorydecoded-&gt;descriptions[$i]-&gt;classid;
          $itemname = $inventorydecoded-&gt;descriptions[$i]-&gt;market_hash_name;
          $tradable = $inventorydecoded-&gt;descriptions[$i]-&gt;tradable;
          $name_color = $inventorydecoded-&gt;descriptions[$i]-&gt;name_color;
  
    ;
  
        }
        $i++;
      } // end of while
        if ($tradable === 1 &amp;&amp; strpos_arr($itemname, $blacklist) == false ) {
              $item_price = ItemPrice::whereItemName($itemname)-&gt;first();
        //     dd(ItemPrice::where('item_name',$itemname)-&gt;first());
              $items[] = ['assetid' =&gt; $asset-&gt;assetid,'classid'=&gt; $classid,'itemname'=&gt;$itemname,'name_color'=&gt;$name_color,'price'=&gt; $item_price-&gt;price];
              $serialized_inventory = serialize($items);
  
        }
    } // end of foreach
  </code></pre>