Laravel DB first() "Trying to get property of non-object"
<p>I run a query using Laravel's DB <code>first()</code> which returns an object, when I check using <code>dd()</code> or <code>vardump()</code>. But when I try to print the value using <code>echo ($promotion-&gt;pp_name);</code> it gives error, but same property shows while <code>dd($promotion-&gt;pp_name);</code></p>

<p><code>&lt;?php dd($promotion-&gt;pp_name); ?&gt;</code> prints <em>"urgent"</em></p>

<p><code>&lt;?php echo ($promotion-&gt;pp_name); ?&gt;</code> but it gives <em>"Trying to get property of non-object"</em>  </p>

<p>Full object dump results: <code>&lt;?php dd($promotion); ?&gt;</code></p>

<pre><code>    {#196 ▼
  +"ppo_id": 23
  +"ppo_prj_id": 68
  +"ppo_pp_id": 4
  +"ppo_updated_date": "2014-05-20"
  +"ppo_status": 1
  +"pp_id": 4
  +"pp_name": "urgent"
  +"pp_dispText": "I want my project to be marked as an urgent project"
  +"pp_amount": "5.00"
  +"pp_updated_date": "2013-08-09"
  +"pp_status": 1
}
</code></pre>

<p>and the function that return this object. </p>

<pre><code>function getProjectPromotion($value='')
{
    $project_id = $value; 

    $promotion =     DB::table('project_promotion_option')
                    -&gt;join('project_promotion', 'project_promotion_option.ppo_pp_id', '=', 'project_promotion.pp_id')
                    -&gt;where('ppo_prj_id',  '=' ,  $project_id )
                    -&gt;first(); 

    return $promotion; 

}
</code></pre>