Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Laravel 5.x Cookbook

You're reading from  Laravel 5.x Cookbook

Product type Book
Published in Sep 2016
Publisher Packt
ISBN-13 9781786462084
Pages 402 pages
Edition 1st Edition
Languages
Authors (2):
Terry Matula Terry Matula
Profile icon Terry Matula
Alfred Nutile Alfred Nutile
Profile icon Alfred Nutile
View More author details

Table of Contents (17) Chapters

Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Setting Up and Installing Laravel 2. Using Composer Packages 3. Routing 4. Building Views and Adding Style 5. Working with Data 6. Adding Angular to Your App 7. Authentication, Security, and Subscriptions 8. Testing and Debugging Your Application 9. Adding Advanced Features to Your App 10. Deploying Your App Index

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…

  1. Install the needed library from https://packagist.org/packages/spatie/laravel-sluggable:

    >composer require spatie/laravel-sluggable 
    
  2. Update the database as needed, so we can save this slug for the user model:

  3. Now is the time for the code to do the alteration on the table:

  4. Then, run the migration:

    >php artisan migrate
    
  5. Update the code in app/User.php as per the package docs:

  6. Let's watch it work...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}