November 30, 2017 —John Koster
The slug
helper method will format the given $title
to resemble a URI slug. It does this through a series of steps:
$title
to ASCII formatting (using the ascii
function, along with the provided $language
);$separator
;The signature of the slug
method is:
1public static function slug(2 $title,3 $separator = '-',4 $language = 'en'5 );
This function will also convert the entire string to its lower cased alternative.
1use Illuminate\Support\Str; 2 3// rebuilding-stillatcom 4echo Str::slug('Rebuilding stillat.com'); 5 6// customizing-the-laravel-artisan-application 7echo Str::slug(' Customizing The Laravel Artisan Application '); 8 9// laravel_artisan_config_command_the_configclear_command10echo Str::slug(11 'Laravel Artisan Config Command: The config:clear Command',12 '_'13 );14 15// laravel_artisan_config_command_the_configclear_command16echo Str::slug(17 'Laravel Artisan Config Command: The config:clear Command',18 '_',19 'en'20 );
str_slug
Helper FunctionThe str_slug
function is a shortcut to calling Str::slug
. This function is declared in the global namespace.
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.