title: Laravel 5 - Save or update
body: <p>I want to store a list of departments in my database.  I do not create the departments in my system, I obtain them from Active Directory.  In the view for departments, I display all the departments.  I also have a button to update departments in the database.</p>
  
  <p>This function at the moment looks like the following</p>
  
  <pre><code>public function updateDepartments()
  {
      $departments = Helper::returnDepartmentsFromLdap();
  
      dd($departments);
  }
  </code></pre>
  
  <p>The dd produces something like the following</p>
  
  <pre><code>array:16 [▼
    0  =&gt; "Department 1"
    8  =&gt; "Department 2"
    21 =&gt; "Department 3"
    22 =&gt; "Department 4"
    29 =&gt; "Department 5"
    43 =&gt; "Department 6"
    47 =&gt; "Department 7"
    48 =&gt; "Department 8"
  ]
  </code></pre>
  
  <p>You have to remember though that this list is not being obtained from my database, it is being obtained from Active Directory.  However, I now want to add them to my database.  So in the same function I do the following</p>
  
  <pre><code>public function updateDepartments()
  {
      $departments = Helper::returnDepartmentsFromLdap();
  
      foreach($departments as $departmentID =&gt; $departmentName) {
          $department = new Department();
          $department-&gt;departmentID = $departmentID;
          $department-&gt;departmentName = $departmentName;
          $department-&gt;save();
      }
  
      return Redirect::route('departments.index')-&gt;with('message', 'Departments updated.');
  }
  </code></pre>
  
  <p>Now the problem with the above is that every time the button is pushed, the database will insert new rows.  Say I push the button for the first time, my database will be populated with the list.  Say I then push it a second time, I do not want the same list added again.  If it already exist in the database, it should overwrite it or something.  It should only perform a save if a new item is in the list.</p>
  
  <p>Is something like this possible?</p>
  
  <p>Thanks</p>