Laravel ucfirst String Helper Function Example

Laravel ucfirst String Helper Function Example; In this tutorial you will learn How to capitalize first letter in Laravel Blade. The ucfirst method returns the given string with the first character capitalized.

The ucfirst helper method is used to uppercase the first letter of a string. It defines only one parameter—$string—which is the string that should have its first letter upper cased.

Here, I will give you full example for simply str ucfirst() method in laravel 5, laravel 6, laravel 7, laravel 8, laravel 9 application.

Solution

use Illuminate\Support\Str;

$converted1 = Str::ucfirst('foo bar');
dd($converted1);
// output -  Foo bar

$converted2 = Str::ucfirst('nice blog');
dd($converted2);
//Nice blog

Example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;

class HomeController extends Controller
{
    public function index()
    {
        $converted1 = Str::ucfirst('foo Bar');
        dd($converted1);
        // output -  Foo bar

       $converted2 = Str::ucfirst('nice blog');
        dd($converted2);
        //Nice blog
    }
}

How to capitalize first letter in Laravel Blade?

{{ ucfirst(trans('messages.welcome')) }}

I hope its work for you.

Leave a Comment