honzahana
1 week ago
344
12
Laravel

Extend Str helper

Posted 1 week ago by honzahana

Is there a way to extend Larave's build in \Illuminate\Support\Str helper? I would like to add new functionalities.

If i create a App\Helpers\Str class which extend original \Illuminate\Support\Str

namespace App\Helpers;

class Str extends \Illuminate\Support\Str {
    public static function removeSpaces(string $value): string
    {
        return preg_replace('/[\s]+/u', '', $value);
    }
}

Fluet access does not work.

Example: Str::of('ahoj, jak se mas?')->removeSpaces()->title()

Do you have any idea?

Please sign in or create an account to participate in this conversation.