Laravel Convert String to Lowercase Example

By Hardik Savani November 5, 2023 Category : Laravel

Hey Friends,

Now, let's see an example of laravel string to lowercase. if you want to see an example of how to convert string to lowercase in laravel then you are in the right place. This post will give you a simple example of laravel convert string to lowercase. you can see laravel str lower helper.

Certainly! In Laravel, you can also use the Str::lower() method from the Illuminate\Support\Str class to convert a string to lowercase. Here's how you can do it.

Make sure you've included the use Illuminate\Support\Str; statement at the top of your file to import the Str class before using the Str::lower() method. This method provides the same functionality as the strtolower() function but is provided as a part of Laravel's helper methods.

let's see a simple example:

Laravel String to Lowercase 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 = 'LARAVEL 10';

$lower = Str::lower($string);

dd($lower);

}

}

Output:

laravel 10

Laravel String to Lowercase in Blade File

you can use it with blade file like this way:

Blade File Code:

<p>{{ Str::lower('LARAVEL 10') }}</p>

Output:

laravel 10

I hope it can help you...

Tags :
Shares