Code Explainers

Code explainers tagged #slugs

php
<?php
 
namespace App\Models;
 

Auto-generating unique slugs in Laravel

eloquent model-events slugs
Intermediate 8 steps
go
package slug
 
import (
	"regexp"

Turning titles into URL slugs in Go

unicode-normalization regexp string-processing
Intermediate 8 steps
typescript
import slugify from "slugify";
 
interface SlugRepository {
  exists(slug: string): Promise<boolean>;

Generating unique URL slugs from titles

slugs normalization uniqueness
Intermediate 6 steps
python
from django.db import models
from django.utils.text import slugify
 
 

Auto-generating unique slugs in Django

slugs orm model-methods
Intermediate 7 steps
ruby
class Post < ApplicationRecord
  before_validation :generate_slug, on: :create
 
  validates :slug, presence: true, uniqueness: true

How a Rails model builds unique slugs

slugs callbacks validations
Intermediate 7 steps
ruby
class Article < ApplicationRecord
  before_validation :generate_slug, on: :create
 
  validates :slug, presence: true, uniqueness: true,

How URL slugs work in Rails

callbacks validations slugs
Intermediate 7 steps