Laravel Convert String to Uppercase Example

By Hardik Savani November 5, 2023 Category : Laravel

Hey Guys,

In this tutorial, you will learn laravel string to uppercase. you can understand a concept of how to convert string to uppercase in laravel. I would like to show you laravel convert string to uppercase. you will learn laravel str upper helper.

Absolutely! To convert a string to uppercase using Laravel's Str::upper() method, follow these steps.

Remember to include the use Illuminate\Support\Str; statement at the top of your file to import the Str class before using the Str::upper() method. This method works similarly to the strtoupper() function, but it's provided as part of Laravel's helper methods.

let's see the simple example:

Laravel String to Uppercase 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';

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

dd($upper);

}

}

Output:

LARAVEL 10

Laravel String to Uppercase in Blade File

you can use it with blade file like this way:

Blade File Code:

<p>{{ Str::upper('laravel 10') }}</p>

Output:

LARAVEL 10

I hope it can help you...

Tags :
Shares