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: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.