laravel Undefined property: stdClass::$
<p>how I can correct this error, I have three tables profils, competences and competences_profil.
I want to recover the competences of each profil, I could retrieve the profils with query builder and competences with eloquent. but when I want to retreive the competence of each profil, I get following error : Undefined property: $ stdClass ::</p>

<pre><code>controller :
        $competences = \App\Competence::All();

     $profils = \DB::table('profils')
            -&gt;select(['profils.*']);

        if($request-&gt;has('varcate')){
                $profils-&gt;join('fonctions','profils.fonctions_id','=','fonctions.id');       
                $profils-&gt;join('categos','fonctions.categos_id','=','categos.id');
                $profils-&gt;where('categos.id','=',$request-&gt;input('varcate'));

        }

        if($request-&gt;has('varfonction')){
            if(!$request-&gt;has('varcate')){   
                $profils-&gt;join('fonctions','profils.fonctions_id','=','fonctions.id');       
            }

            $profils-&gt;where('fonctions.id','=',$request-&gt;input('varfonction'));
        }

        if($request-&gt;has('varstate')){
                $profils-&gt;join('citys','profils.citys_id','=','citys.id');       
                $profils-&gt;join('states','citys.state_id','=','states.id');
                $profils-&gt;where('states.id','=',$request-&gt;input('varstate'));

        }

     if($request-&gt;has('varcity')){
            if(!$request-&gt;has('varstate')){   
                $profils-&gt;join('citys','profils.citys_id','=','citys.id');       
            }

            $profils-&gt;where('citys.id','=',$request-&gt;input('varcity'));
        }

      $profils = $profils-&gt;paginate(30);
</code></pre>

<p>model :
    competence
            public function profils()
        {
            return $this->belongsToMany('App\Profils');
        }</p>

<pre><code>profils
        public function competences()
    {
        return $this-&gt;belongsToMany('App\Competence');
    }

view :
@foreach($profils as $profil) 
        @foreach($profil-&gt;competences as $competence) 
          {{$competence-&gt;titre}}
        @endforeach
@endforeach
</code></pre>