laravel-localization
laravel-localization copied to clipboard
Route model binding is not work
Describe the bug Route model binding is not working, why?
To Reproduce In web.php:
Route::get('/page/{page}', function (App\Page $page) { return $page; });
return is not exists model. When I remove middleware localize
all working. How I can fix it?
My model Page:
use Spatie\Translatable\HasTranslations;
class Page extends Model
{
use HasTranslations;
protected $guarded = [];
protected $translatable = ['title', 'description', 'keywords', 'body'];
public function getRouteKeyName()
{
return 'slug';
}
public function path()
{
return "/" . app()->getLocale() . "/page/{$this->slug}";
}
}
I think you posted this in the wrong repository. You seem to use https://github.com/spatie/laravel-translatable
@iwasherefirst2 no. When I remove this middleware:
->middleware(['localize', 'localeCookieRedirect', 'localizationRedirect', 'localeViewPath'])
all working good.
Still having the issue? Did you follow the steps and the video from https://github.com/mcamara/laravel-localization#translated-routes ? Can you show us the relevant code sections that are mentioned in the guide/video?