Hello Devs, 

In this tutorial, we will learn Laravel str snake() function Example

the str::snake method converts the given string to snake_case.

Follow this step-by-step guide below. 

Example:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\FileController;
use Illuminate\Support\Str;

class HomeController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $converted1 = Str::snake('fooBar');
        dd($converted1);
        // output - foo_bar

       $converted2 = Str::snake('niceBlog');
        dd($converted2);
        //nice_blog
    }
}

Output: 

"foo_bar"
"nice_blog"


May this example help you.