strap snouted brown snake

How To Convert Any Laravel String Into Snake Case String

Laravel Str Support library is very useful when it comes to String methods. It gives us ways and means to do achieve different string conversions. See the tutorial below how we can convert any string into snake case string in Laravel with perfection. This tutorial is simple to understand and you’d need a minute to understand it.

Raw string: store products count

Snake Case String: store_products_count

Here goes the code to convert any string to Snake Case using snake() 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';
		$converted1 = Str::snake($str);
		echo $converted1;
	}
}

Please check Laravel 8.0 docs for detailed documentation. If you have any problem just leave a comment in comments section. We will address that.