Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.25k stars 157 forks source link

route with translated post slug #272

Closed IslamYCB closed 2 years ago

IslamYCB commented 2 years ago

Hello guys,

how do I get the post translated slug in route in my routes I'm using:

Route::get('posts/{post:slug}', [PostController::class, 'show'])->name('post');

but of course if slug is translated this wouldn't work, so how do I refer for the translated slug in the route instead of {post:slug} since this doesn't work

Gummibeer commented 2 years ago

Hey,

this only works with a custom substitution middleware, like that one in the enum package: https://github.com/spatie/laravel-enum/blob/main/src/Http/Middleware/SubstituteEnumBindings.php

Or by resolving the slug in your controller using the whereTranslation() scope. https://docs.astrotomic.info/laravel-translatable/package/scopes#where-translation

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days