All packages
Sluggable for Laravel
DI and actions
The facade is sugar — there are three equivalent entry points, and the choice is yours:
- The Slugs facade — the shortest, and the recommended default.
- The manager, injected through the constructor — the same API as an explicit dependency, with no static calls. RoundlyConsulting\Sluggable\SlugManager is the facade root.
- Actions — single-purpose classes with an execute() method, for composing into your own actions, jobs and commands.
Injecting the manager
use RoundlyConsulting\Sluggable\Enums\RegenerationMode;
use RoundlyConsulting\Sluggable\SlugManager;
final class BackfillSlugs
{
public function __construct(private SlugManager $slugs) {}
public function __invoke(): void
{
$this->slugs->model(Product::class)->regenerate(mode: RegenerationMode::Missing);
}
}Running an action
Each facade method runs one action, resolved from the container. The actions take a DTO — RegenerateSlugsData for regeneration, as here:
use RoundlyConsulting\Sluggable\Actions\RegenerateSlugsAction;
use RoundlyConsulting\Sluggable\DataTransferObjects\RegenerateSlugsData;
use RoundlyConsulting\Sluggable\Enums\RegenerationMode;
$report = app(RegenerateSlugsAction::class)->execute(
new RegenerateSlugsData(Product::class, mode: RegenerationMode::Stale),
); // RegenerationReport| Method | Action |
|---|---|
apply(), recompute(), regenerate() | GenerateSlugsAction |
model()->regenerate() | RegenerateSlugsAction |
model()->queueRegeneration() | QueueSlugRegenerationAction (dispatches RegenerateSlugsJob) |
model()->duplicates() | FindDuplicateSlugsAction |
model()->findInHistory() | ResolveSlugFromHistoryAction |
model()->indexes() | SlugIndexes::forModel() (schema helper, also usable in migrations) |
RecordSlugHistoryAction is internal — a step of the save pipeline; history is recorded by saving, not by calling it.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.