title: Remove Whitespace from table inputs
body: <p>I have an active database with username columns but I later discovered it has a lot of whitespace which causes a not found error when I try to compare a record against itself. So I am trying to remove all white space from all user names, here is the challenge:</p>
  
  <pre><code>$user = (User::where("unique_id", 1)-&gt;first())-&gt;username;
      $string = preg_replace('/\s+/', '', $user);
     $dd = DB::table("users")-&gt;where("unique_id", 1)
     -&gt;update(["username"=&gt;$string]);
  </code></pre>
  
  <p>Where I select a single query like the above and change the the username it works,</p>
  
  <p>but when I try to change the whole usernames in the database at once it does not work.</p>
  
  <pre><code>$user = User::all();
      foreach($user as $user){
  
          $username = preg_replace('/\s+/', '', $user-&gt;username);
          // $sponsor = preg_replace('/\s+/', '', $user-&gt;sponsor_username);
          DB::table("users")-&gt;where("unique_id", $user-&gt;id)-&gt;update(["username"=&gt;$username]);
      }
  </code></pre>