How to Replace Multiple Strings in a Single Value in Laravel
In this lesson, we are going to see how to replace multiple strings in a single value in Laravel, the replaceArray helper method is used to replace multiple strings in a given value.
The Str::replaceArray helper method
The replaceArray() method replaces multiple strings in a given value.
use Illuminate\Support\Str;
$query = 'SELECT ?, ? FROM users';
$query = Str::replaceArray('?', ['name', 'email'], $query);
echo $query;
// Returns "SELECT name, email FROM users"