How to Replace String in Laravel?
Hey Developer,
This extensive guide will teach you how to replace string in laravel. I would like to share with you laravel string replace all. We will use laravel string replace example. If you have a question about laravel str_replace then I will give a simple example with a solution.
We will use Str facade to replace string in laravel. i will give you few examples to replace string in laravel. so, let's see the simple example:
Laravel Replace String in Controller
you can use it with controller like this way:
Controller Code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$string = 'He is Paresh';
$replaced = Str::replace('Paresh', 'Hardik', $string);
dd($replaced);
}
}
Output:
He is Hardik
Laravel Replace String in Blade File
you can use it with blade file like this way:
Blade File Code:
<p>{{ Str::replace('Paresh', 'Hardik', 'He is Paresh') }}</p>
Output:
He is Hardik
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel String Contains Case Insensitive Example
- Laravel Stripe Checkout Payment Integration Example
- How to Convert String to Array Conversion in Laravel?
- How to Add Dynamic Carousel Slider in Laravel?
- How to Install and Use Laravel Debugbar?
- Laravel PayPal Send Payment to Email Example
- How to Delete All Records Older Than 30 Days in Laravel?
- Laravel Delete All Records Older Than 7 Days Example
- Laravel Artisan Command to Create Migration and Model Example
- Laravel Eloquent Always Load Model Relation Example
- How to Stop Running Queue Jobs in Laravel?
- Laravel Queue Process Timeout Error Solved
- How to Define Fallback Routes in Laravel?