DEV Community

Cover image for Laravel 8 String studly() helper function Example
Code And Deploy
Code And Deploy

Posted on

3 2

Laravel 8 String studly() helper function Example

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/laravel-8-string-studly-helper-function-example

In this post, I will show you an example of a Laravel 8 string helper called studly. This function will help us to convert any strings to a studly case format. This is useful if you are processing a generated function for a method or class generator or in any text processing. To start with studly() helper function we need to import it to your class.

use Illuminate\Support\Str;
Enter fullscreen mode Exit fullscreen mode

Then calling the helper function with Str class. See the below example:

Str::studly('foo_bar')
Enter fullscreen mode Exit fullscreen mode

The advantage of this Laravel helper function will support strings that have space, underscore and hypen. See below the actual code example.

Laravel Studly Example:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;

class HomeController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $studly1 = Str::studly('foo_bar');

        print_r($studly1);
        // output - FooBar

        echo '<br>';

        $studly2 = Str::studly('code and deploy');

        print_r($studly2);
        // output - CodeAndDeploy

        echo '<br>';

        $studly3 = Str::studly('free-tutorials');

        print_r($studly3);
        // output - FreeTutorials

        echo '<br>';

    }
}
Enter fullscreen mode Exit fullscreen mode

Laravel Studly Result:

FooBar
CodeAndDeploy
FreeTutorials

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/laravel-8-string-studly-helper-function-example if you want to download this code.

Happy coding :)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more