title: How to make shortest code?
body: <p>I use the following code to insert multi array to database:</p>
  
  <pre><code>foreach($request-&gt;category as $k =&gt; $v){
                  $category[] = array(
                      "category_id" =&gt; $v,
                      "announcement_id" =&gt; $announcement-&gt;id
                  );
              }
  
              AnnouncementCategory::insert($category);
  </code></pre>
  
  <p>So, input data is POST array <code>$request-&gt;category</code>.
  I need  to refactoring this code</p>
  
  <p>I tried this code:</p>
  
  <pre><code>$announcement-&gt;categories()-&gt;attach($request-&gt;category);
  </code></pre>
  
  <p>In model <code>Announcement</code> I have:</p>
  
  <pre><code> public function categories()
      {
          return $this-&gt;hasMany("App\AnnouncementCategory", "announcement_id", "id");
      }
  </code></pre>