Astrotomic / laravel-translatable

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

defining getRouteKeyName() on a translatable field fails #254

Closed johgh closed 2 years ago

johgh commented 2 years ago

I get a query exception when retrieving my post by slug in my controller

I have in Post model: public function getRouteKeyName() { return 'slug'; }

I declare slug as a translatable field in post_translations migration

When I retrieve a Post with route binding in my controller: public function show(Post $post) { it throws the query exception shown

I am using Laravel 8.

The exception shows how is trying to retrieve the field from posts table instead of posts_translations: Query exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'slug' in 'where clause' (SQL: select * from posts where slug = XXX

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