fix: Use slug for Document route model binding

- Add getRouteKeyName() to return 'slug' for Document model
- Add resolveRouteBinding() to support both slug and ID lookups
- Update QuickSwitcher to use slug instead of ID
- Update quick-switcher blade to use slug in routes

This ensures URLs use readable slugs (e.g., /documents/home)
while maintaining backwards compatibility with ID-based URLs
This commit is contained in:
2025-11-29 17:22:17 +09:00
parent 893d3c7a69
commit ac56889a87
3 changed files with 35 additions and 4 deletions
+31
View File
@@ -19,6 +19,37 @@ class Document extends Model
{
use SoftDeletes;
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName(): string
{
return 'slug';
}
/**
* Retrieve the model for a bound value.
* Supports both slug and ID for backwards compatibility.
*
* @param mixed $value
* @param string|null $field
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function resolveRouteBinding($value, $field = null)
{
// First try to find by slug
$document = $this->where('slug', $value)->first();
// If not found by slug, try by ID (for backwards compatibility)
if (!$document && is_numeric($value)) {
$document = $this->where('id', $value)->first();
}
return $document;
}
/**
* The attributes that are mass assignable.
*