$img->setAttribute('class', 'img-fluid');
This sets the class
field to a new value. Simply change this line to
$classes = $img->getAttribute('class');
$img->setAttribute('class', $classes . ' img-fluid');
$img->setAttribute('class', 'img-fluid');
This sets the class
field to a new value. Simply change this line to
$classes = $img->getAttribute('class');
$img->setAttribute('class', $classes . ' img-fluid');