My String from name Column
john_items.3
I want to fetch all these names that start with the john and replace all of them with smith and update columns like
**john_items.3**
will become
**smith_items.3**
My String from name Column
john_items.3
I want to fetch all these names that start with the john and replace all of them with smith and update columns like
**john_items.3**
will become
**smith_items.3**
$replacedItems = \App\Models\ModelName::where('name', 'LIKE','john'.'%' )
->get()
->map(function ($item) {
$item->name = str_replace('john', 'smith', $item->name);
$item->save();
return $item;
});
// Print all
dd($replacedItems->toArray());