ItSolutionStuff.com

How to Capitalize First Letter of String in Laravel?

By Hardik Savani • November 5, 2023
Laravel

Hey Folks,

This tutorial will give you an example of laravel string capitalize. We will use laravel capitalize first letter. This article will give you a simple example of how to capitalize first letter in laravel. you'll learn how to capitalize string in laravel. follow the below example for laravel str::ucfirst() helper example.

The Str::ucfirst() method in Laravel is used to make the first character of a string uppercase. It is a convenient method to capitalize the first character of a string.

Here's an example of how to use it:

In this example, the Str::ucfirst() method is applied to the $string variable, and it returns a new string with the first character capitalized. The resulting string is then echoed, displaying "Laravel is awesome".

let's see the simple example:

Laravel Capitalize First Letter of 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 = 'laravel is awesome';

$ucfirstString = Str::ucfirst($string);

dd($ucfirstString);

}

}

Output:

Laravel is awesome

Laravel Capitalize First Letter of String in Blade File

you can use it with blade file like this way:

Blade File Code:

<p>{{ Str::ucfirst("laravel is awesome") }}</p>

Output:

Laravel is awesome

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Check String is URL or Not in Laravel?

Read Now →

Laravel Check If String Starts with Specific Value Example

Read Now →

How to Convert String to CamelCase in Laravel?

Read Now →

How to Get Length of String in Laravel?

Read Now →

Laravel Convert String to Uppercase Example

Read Now →

Laravel Convert String to Lowercase Example

Read Now →

Laravel Import Large CSV File Using Queue Example

Read Now →

How to Replace String in Laravel?

Read Now →

How to Install and Setup Supervisor in Ubuntu for Laravel?

Read Now →

Laravel String Contains Case Insensitive Example

Read Now →

Laravel Stripe Checkout Payment Integration Example

Read Now →

How to Convert String to Array Conversion in Laravel?

Read Now →

How to Add Dynamic Carousel Slider in Laravel?

Read Now →