Site Admin
Site Admin Founder of MeaningArticles
1112 Views

Laravel ucfirst() function Example

Hello Dev.

In this small article, I will learn you how to use laravel str ucfirst() function example. We will show example of ucfirst function in laravel. The ucfirst method returns the given string with the first character capitalized.

Here, I will give you full example for simply str ucfirst() method in laravel as bellow.


The Trick

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

$converted2 = Str::ucfirst('niceBlog');
dd($converted2);
//Nice Blog


Example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\FileController;
use Illuminate\Support\Str;

class HomeController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $converted1 = Str::ucfirst('fooBar');
        dd($converted1);
        // output -  Foo bar

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

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.