2

Does a Laravel has an included function to convert a string to an url? Or should I use some standart PHP libraries? But with standard library there is a problem with duplicating url... So there should be a script for every model..?

Example:

'Apple Cake'=>'apple-cake'
1
  • @MartinBean I have added an example. String in my case is some kind of title of an article for example Commented Jan 17, 2017 at 8:54

2 Answers 2

7

If you’re wanting to convert a title-case word to a URL-friendly string, then you can use the Str::slug() method:

use Illuminate\Support\Str;

$slug = Str::slug('Apple Cake'); // apple-cake
Sign up to request clarification or add additional context in comments.

2 Comments

This function is not included in "standard" Laravel anymore. You can either include the package "laravel/helpers" or use Str::slug('Apple Cake');
@Arangor Indeed, the helper function’s been removed in the near-four years since I wrote this answer. I’ve updated it with a version that will working in newer (as well as older) versions of Laravel.
0

I also have found https://github.com/cviebrock/eloquent-sluggable slug maker for Laravel, if someone will have the same problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.