Rename assets to lowercase
Just tested your code and it worked as you'd expect if you leave off the extra getExtension() call (the filename property already includes the extension).

$filename = strtolower($asset-&gt;filename);


If it's not saving for you with that, you've got some other error happening elsewhere.