How to generate seo-friendly url slug automatically

  Tue 20 / 06 / 2023

  Posted by: Muhammad Siddique

Category : Laravel

Tags : laravel , php

Description

AoA,  I am Neubie on Laravel. Please help with how to generate SEO-Friendly URL Slug Automatically using Ajax.                                                                                                                                                                                                                                                                                              


  Answered by CDL

W.salam, yes dear you can generate slug using Str::slug facade. 

For example, you have a title variable and you want to generate a slug from it.

~~~

$title = 'Career Development Lab';

$slug = \Str::slug($title);

// output 

Career-Development-Lab

~~~

For more unique slugs you can add the rand function with the slug or you can use library sluggableto generate a unique slug.  For more information visit the below link to read the full article. 

Generate Slug in Laravel.


For Ajax calls you can send ajax call to server to generate a slug. Follow below article.

Generate slug in Laravel using ajax call


Solved
  Comment   Share
1 Like   0 Comments