How To Convert Any String Into Camel Case In Laravel?

Laravel Str Support library is very useful when it comes to String methods. Lets see below how easily we can learn to convert any string into the Camel case in Laravel without breaking much sweat.

Raw string: store products count

Camel Case String: storeProductsCount

Laravel Str support library has given us liberty to use many methods to manipulate strings.  To see a better example of that let’s see below how easily we can convert any string to Camel Case using camel() function.

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Str;


class HomeController extends Controller
{
	/**
	 * Show the application dashboard.
	 *
	 * @return \Illuminate\Contracts\Support\Renderable
	 */
	public function index()
	{
		$str = 'store products count';
		$converted = Str::camel($str);
		echo $converted;
	}
}

 

Please check Laravel 8.0 docs for detailed documentation. It will be hard to read but do not worry if you have any problem just leave a comment in comments section. We appreciate that.