Adding clean URLS for the users profile page
There is nothing like sending a user to profile/44444-55555-6666-7777
or any page in our application. In this recipe, I will add some slugs to the user profile page.
Note
Slug? Semantic URL
Semantic URLs, also sometimes referred to as clean URLs, RESTful URLs, user-friendly URLs, or search engine-friendly URLs…
Refer to Wikipedia for more information: https://en.wikipedia.org/wiki/Semantic_URL and see an example slug in that URL.
Getting ready
A fresh install of Laravel can work for you with a database for making users for whom you can add a Slug.
How to do it…
Install the needed library from https://packagist.org/packages/spatie/laravel-sluggable:
>composer require spatie/laravel-sluggable
Update the database as needed, so we can save this slug for the user model:
Now is the time for the code to do the alteration on the table:
Then, run the migration:
>php artisan migrate
Update the code in
app/User.php
as per the package docs:Let's watch it work...