title: Using isDirty in Laravel
body: <p>I'm using the <code>isDirty()</code> method in my controller to check if any field is changed. Then I am saving the old data of a field and the new data in a <code>table</code>. The code is working fine; however, how can I <code>optimize</code> this code?</p>
  
  <p>By using the below code, I will have to write each field name again and again. If <code>request-&gt;all()</code> has 20 fields, but I want to check six fields if they are modified, how can I pass only <code>6 fields</code> in the below code, without repeating?</p>
  
  <p><strong>Controller</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>if ($teacher-&gt;isDirty('field1')) {
      $new_data = $teacher-&gt;field1;
      $old_data = $teacher-&gt;getOriginal('field1');
  
      DB::table('teacher_logs')-&gt;insert(
          [
              'user_id' =&gt; $user-&gt;id,
              'teacher_id' =&gt; $teacher-&gt;id,
              'old_value' =&gt; $old_data,
              'new_value' =&gt; $new_data,
              'column_changed' =&gt; "First Name",
          ]);
  }
  </code></pre>