title: Getting user related buildings using whereHas in User model eloquent
body: <p>I have the following method in App\User Model file </p>
  
  <pre><code>Public function buildings(){
          return Building::whereHas('area', function ($q) {
              $q-&gt;whereHas('users', function ($q) {
                  $q-&gt;where('users.id', auth()-&gt;id());
              });
          })-&gt;get();
      }
  </code></pre>
  
  <p>When i try to get the user buildings in View file, i got this error :</p>
  
  <pre><code>@foreach (Auth::user()-&gt;buildings as $b)
      {{$b-&gt;name}}
                  @endforeach
  </code></pre>
  
  <p>App\User::buildings must return a relationship instance. (View: C:\xampp\htdocs\hse\resources\views\observations\form_observation.blade.php)</p>
  
  <p>I tried the code in web.php and it works  that means that the relationship setting is perfect, but i want it to work in User Model</p>
  
  <pre><code>Route::get('/', function () {
      return App\Building::whereHas('area', function ($q) {
  $q-&gt;whereHas('users', function ($q){
      $q-&gt;where('users.id',11);
  });
      })-&gt;get();
  });
  </code></pre>