title: Saving multiple IDs in a HasMany Eloquent relationship
body: <p>I have a model <code>Foo</code>, which has many <code>Bar</code>s:</p>
  
  <pre><code>class Foo extends Model
  {
      public function bars()
      {
          return $this-&gt;hasMany('App\Bar');
      }
  }
  
  class Bar extends Model
  {
      public function foo()
      {
          return $this-&gt;belongsTo('App\Foo');
      }
  }
  </code></pre>
  
  <p>When saving a new <code>Foo</code>, the request payload comes with an array of <code>Bar</code> ids. I want to save these at the same time. This works:</p>
  
  <pre><code>public function store(StoreFoo $request)
  {
      $foo = Foo::create($request-&gt;validated());
      foreach ($request-&gt;barIds as $barId) {
          $foo-&gt;bars()-&gt;create(['bar_id' =&gt; $barId]);
      }
  }
  </code></pre>
  
  <p>My question is: is there a way to do this without a loop? I've tried <code>sync</code> and <code>attach</code> but these aren't applicable in this case.</p>