title: Maximum stack depth exceeded problem in many to many toArray() overriding
body: <p>i have 2 models, <strong>User</strong> and <strong>Department</strong>. these two have <strong>many to many</strong> relation with each other. when i try to relation field to <strong>toArray()</strong> method inside Model class, i get <strong>Maximum stack depth exceeded</strong> error.</p>
  
  <p><strong>Department Model :</strong> </p>
  
  <pre><code>class Department extends Model
  {
      public function users()
      {
          return $this-&gt;belongsToMany(User::class);
      }
  
      public function toArray()
      {
          $arr = parent::toArray();
          $arr['users'] = $this-&gt;users;
          return $arr;
      }
  }
  </code></pre>
  
  <p><strong>User Model :</strong> </p>
  
  <pre><code>class User extends Model
  {
      public function departments()
      {
          return $this-&gt;belongsToMany(Department::class);
      }
  
      public function toArray()
      {
          $arr = parent::toArray();
          $arr['departments'] = $this-&gt;departments;
          return $arr;
      }
  }
  </code></pre>
  
  <p>what is the right way to have this kind of JSON output?</p>
  
  <p>/api/departments : </p>
  
  <pre><code>{
      "success": true,
      "data": [
          {
              "id": 1,
              "caption": "asd",
              "status": "active",
              "users": []
          }
      ]
  }
  </code></pre>
  
  <p>/api/users :</p>
  
  <pre><code>{
      "success": true,
      "data": [
          {
              "id": 1,
              "username": "asdasd",
              "email": "m@m.m",
              "status": "active",
              "departments": []
          }
      ]
  }
  </code></pre>