title: How to Define Relations and Get All Records with Relations in Laravel?
body: <p>I want to define a relationship between tables, and I don't know where I'm going wrong.</p>
  
  <p>These are my tables:</p>
  
  <p><strong>users</strong></p>
  
  <pre>
      -id
      -email
      -level
  </pre>
  
  <p><strong>restaurants</strong></p>
  
  <pre>
      -id
      -name
      -user_id
  </pre>
  
  <p><strong>menus</strong></p>
  
  <pre>
      -id
      -name
  </pre>
  
  <p><strong>restaurant_menu</strong></p>
  
  <pre>
      -restaurant_id
      -menu_id
      -price
  </pre>
  
  <p>In the <code>users</code> table, the field <code>level</code> will set by me with two words: <code>[user]</code> or <code>[restaurant]</code>.</p>
  
  <p><strong>User Model</strong></p>
  
  <pre><code>public function restaurant(){
      return $this-&gt;hasOne(Restaurant::class);
  }
  </code></pre>
  
  <p><strong>Restaurant Model</strong></p>
  
  <pre><code>public function menus(){
      return $this-&gt;hasMany(Menu::class);
  }
  </code></pre>
  
  <p><strong>Menu Model</strong> </p>
  
  <pre><code>public function restaurants(){
      return $this-&gt;belongsTo(Restaurant::class);
  }
  </code></pre>
  
  <p>I expect the output of this code:</p>
  
  <pre><code>$result = $restaurant-&gt;where('id',2)-&gt;menus()-&gt;get(); 
  </code></pre>
  
  <p>To be records and relations, but i get the following error.</p>
  
  <blockquote>
    <p>BadMethodCallException
    Call to undefined method Illuminate\Database\Eloquent\Builder::menus()</p>
  </blockquote>
  
  <p>What should I do?</p>