How to Convert String to CamelCase in 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...
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
- 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?
- How to Install and Use Laravel Debugbar?
- Laravel PayPal Send Payment to Email Example
- How to Delete All Records Older Than 30 Days in Laravel?
- Laravel Artisan Command to Create Migration and Model Example