Laravel ucfirst() function Example

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

2447

11-02-2021


Hi Guys,

In this blog,I will 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.

solution


$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

}

}

Output

"Foo bar"

"Nice blog"

It Will help you...