Hello,
There are multiple ways to do it.
You can use the map function on the collection:
$items = Item::select('name', 'description')->get()->map(static function ($item): Item {
$item->description = preg_replace('Search', 'Replace', $item->description);
return $item;
});
$content = view('items', compact('item'));
$encodeContent = mb_convert_encoding($content, 'Windows-1252', 'auto');
Another option is to use an accessor on your model:
// in your model class
public function getReplacedDescriptionAttribute():string
{
return preg_replace('Search', 'Replace', $this->description);
}
Then you can use replaced_description in your view.
@foreach($items as $item)
"{!!$item->name!!}";"{!!$item->replaced_description!!}";
@endforeach
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community