How to Capitalize First Letter of String in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check String is URL or Not in Laravel?
- Laravel Check If String Starts with Specific Value Example
- How to Convert String to CamelCase in Laravel?
- How to Get Length of String in Laravel?
- Laravel Convert String to Uppercase Example
- Laravel Convert String to Lowercase Example
- Laravel Import Large CSV File Using Queue Example
- How to Replace String in Laravel?
- How to Install and Setup Supervisor in Ubuntu for Laravel?
- Laravel String Contains Case Insensitive Example
- Laravel Stripe Checkout Payment Integration Example
- How to Convert String to Array Conversion in Laravel?
- How to Add Dynamic Carousel Slider in Laravel?