Symptom: URLs with leading/trailing slashes return 404.
Since v1.1.0 slashes are auto-trimmed, but the root cause is usually a urlStrategy() that concatenates nullable values:
// Produces "/product" when parent is null
return $this->parent?->getSlug() . '/' . Str::slug($this->name);Fix by guarding the prefix:
public function urlStrategy($language, $locale): string
{
$parentSlug = $this->category?->getSlug($language);
return $parentSlug
? $parentSlug . '/' . Str::slug($this->name, '-', $locale)
: Str::slug($this->name, '-', $locale);
}Cannot generate URL: empty slug for App\Models\Product (ID: 123).
Common causes:
urlStrategy()returns an empty string or null- The slug is only slashes (e.g.
'/') — empty after trimming - The model attribute used for the slug is empty
Add a guard in your strategy:
public function urlStrategy($language, $locale): string
{
if (empty($this->name)) {
throw new \RuntimeException("Cannot generate URL: product name is empty (ID: {$this->id})");
}
return Str::slug($this->name, '-', $locale);
}TypeError: Argument #2 ($url) must be of type ?string, Illuminate\Routing\UrlGenerator given
This happens when passing null to the url() helper. Since v1.1.0 getSlug() returns an empty string instead of null, but on older versions use the null coalescing operator:
$url = url($model->relative_url ?? '');Checklist:
- Does the model use the
HasUniqueUrlstrait? - Are
urlStrategy()andurlHandler()implemented? - Is
isAutoGenerateUrls()returningtrue(or not overridden)? - Is the catch-all route registered at the end of
routes/web.php? - Have you run the migration? (
php artisan migrate)
Force generation for models with auto-generate disabled:
php artisan urls:generate --model=Product --forceInvalid slug 'admin' for App\Models\Page (ID: 1): slug is reserved.
This only occurs when validate_slugs is enabled in config. Either choose a different slug or remove the entry from the reserved list:
// config/unique-urls.php
'reserved_slugs' => [
// 'admin', // removed
'api',
'login',
],