ItSolutionStuff.com

How to Convert String to CamelCase in Laravel?

By Hardik Savani • November 5, 2023
Laravel

Hey Friends,

This tutorial shows you How to convert string to camelCase in laravel. I’m going to show you about laravel string camelcase example. I would like to share with you laravel str camelcase. you can see how to convert string to camelcase in laravel.

The Str::camel() method in Laravel is used to convert a string to camel case. It converts a string that is separated by underscores, hyphens, or spaces into camel case by capitalizing the first letter of each word (except for the first word). Here's an example:

In this example, Str::camel() converts the string 'hello_world' into 'helloWorld' by removing the underscore and capitalizing the first letter of the second word.

let's see the simple example:

Laravel String to CamelCase 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 = "hello_world";

$newString = Str::camel($string);

dd($newString);

}

}

Output:

helloWorld

Laravel String to CamelCase in Blade File

you can use it with blade file like this way:

Blade File Code:

<p>{{ Str::camel('hello_world') }}</p>

Output:

helloWorld

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

ā˜…

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 →
ā˜…

How to Install and Use Laravel Debugbar?

Read Now →
ā˜…

Laravel PayPal Send Payment to Email Example

Read Now →
ā˜…

How to Delete All Records Older Than 30 Days in Laravel?

Read Now →
ā˜…

Laravel Artisan Command to Create Migration and Model Example

Read Now →