Screen Shot 2021 03 22 at 9.27.11 PM

How To Convert Strings To Kebab Case In Laravel?

Laravel Str Support library helps us understand strings well and manipulate them with broad and easy examples. We have shown the tutorial below how you can  convert Laravel strings into Kebab case. 

Raw string: store products count

Kebab Case String: store-products-count

We are using kebab() function to do that. Lets write the code about it below.

<?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::kebab( $str );
		echo $converted;
	}
}

For detailed information check Laravel 8.0 docs. If you find any thing problematic regarding kebab case string conversion let’s know in the comments below.