Skip to main content

Commands

make:polyslug​

php artisan make:polyslug Page
php artisan make:polyslug Blog/Page

Scaffolds a sluggable Eloquent model in the application's Models namespace, pre-wired with the #[Polyslug] attribute, the HasPolyslug trait and the Sluggable interface. The generated attribute uses source: 'title' — change it to the column your model actually slugs from.

The root namespace is the one the application's composer.json maps to app/, so a default application gets App\Models\Page in app/Models/Page.php. A namespace in the name becomes a subdirectory: Blog/Page scaffolds App\Models\Blog\Page in app/Models/Blog/Page.php.

An existing file is never overwritten, and a name PHP reserves, such as Class or List, is refused. In both cases the command says why and exits non-zero. Called without a name in an interactive terminal, it asks for one.

ArgumentDescription
nameThe model class name, optionally with a namespace below Models, separated by / or \. Each segment is studly-cased, so blog/landing-page yields Blog\LandingPage.

polyslug:backfill​

php artisan polyslug:backfill "App\Models\Page"
php artisan polyslug:backfill "App\Models\Page" --locale=de
php artisan polyslug:backfill "App\Models\Page" --queue --chunk=500
php artisan polyslug:backfill "App\Models\Page" --queue --on-queue=bulk --on-connection=redis

Backfills current slugs for a sluggable model's existing rows. Rows that already have a current slug for the target locale are skipped, so the command is safe to run repeatedly.

Argument / optionDefaultDescription
model(required)The fully-qualified model class. Must be an Eloquent model implementing Sluggable, or the command errors and exits non-zero.
--localethe app localeLocale to backfill.
--queueoffDispatch chunked Polyslug\Jobs\BackfillSlugsJob jobs instead of running inline.
--chunk1000Rows per queued job.
--on-queuepolyslug.backfill.queueQueue name for the dispatched jobs. A backfill on the default queue blocks everything behind it for as long as the table takes.
--on-connectionpolyslug.backfill.connectionQueue connection for the dispatched jobs.

See Backfilling existing rows.

polyslug:sitemap​

php artisan polyslug:sitemap --path=public/sitemap.xml

Generates an XML sitemap with hreflang alternates for the models registered in polyslug.sitemap.types. Rows are read in keyset chunks; the rendered document is assembled in memory before it is written.

OptionDefaultDescription
--path(none)Write the XML to this file. Without it, the XML goes to standard output.
--base-urlapp.urlPublic URL the sitemap files are served from. Used by the index when the set is split across several files, so the index can point at them absolutely. Without either this or a configured app.url, a split set has no absolute URL to name and the command says so.

Requires a bound Polyslug\Contracts\PolyslugUrlResolver; without one the command prints an error and exits non-zero. See Sitemaps.

polyslug:forget-orphans​

php artisan polyslug:forget-orphans
php artisan polyslug:forget-orphans --dry-run
php artisan polyslug:forget-orphans --type="App\Models\Deliberation"

Forgets what Polyslug holds for records that no longer exist: the slug rows, the short links and the identity tokens of every key whose record is gone. A foreign-key cascade, a delete from before an application called polyslugForget(), or a new way of deleting that leaves the call out keeps them, with text from the records' titles in the slugs. Whether a record exists is asked without global scopes, so a record in the trash counts as present and keeps everything.

What happens to the rows is what polyslugForget() does: the slug rows are deleted, and the short links and tokens move to the forgotten type and keep their tokens taken. The keys are read and forgotten a thousand at a time, and running it again changes nothing.

It looks at every model type the short links, the identity tokens and the slug rows on the slug model's connection hold rows for. A model whose slugs live on a connection of its own and that has no short link or token is named with --type. A type that names no model using HasPolyslug is reported and left as it is.

Schedule it, so that whatever a cascade leaves is forgotten by the next run:

// routes/console.php
use Illuminate\Support\Facades\Schedule;

Schedule::command('polyslug:forget-orphans')->daily();
OptionDescription
--type=*A model type to look at, as stored or as its class. Every type the stores hold rows for when left out.
--dry-runCount the records that are gone, per type, and change nothing.
--isolatedDo not start while another run of the command is still going.

polyslug:doctor​

php artisan polyslug:doctor

Diagnoses the setup: the encoder configuration, the model replacements, the status settings, the token settings, how much room the token spaces have left, the uniqueness-guaranteeing indexes, and the resolution gates. It exits non-zero if the configured encoder — or a legacy decoder — is not a valid IdentityEncoder or cannot be built, if an entry in polyslug.models is one Polyslug ignores, if a status setting is outside its kind, if a token length or alphabet cannot build a scheme, or if a required unique index is missing (for example because the migrations never ran).

The token-settings check is the one to run after editing polyslug.random_token, polyslug.sequential_token or polyslug.short_links: without it, an unbuildable setting first refuses while a URL is being rendered, in production.

It also reports every registered type that never overrode polyslugResolveQuery(). That is a report, not a failure: such a model resolves any slug to any row, which is correct for public content and an authorization gap for anything owner-scoped. The command cannot tell which you meant, so it names the models and leaves the call to you.

It also reports how full each token width is, once a width is at least a quarter used:

! identity tokens: 400 of 1,296 2-character tokens are taken (31%).
New tokens widen to 3 characters as this fills.

Also a report and never a failure — a filling width is not a fault, and on a counted scheme it is exactly what is supposed to happen. It is there so a short token setting that is running out is visible before it runs out.

See Diagnostics.