mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.35k stars 508 forks source link

Route model binding is not work #690

Open ExsyDev opened 4 years ago

ExsyDev commented 4 years ago

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}";
      }
  }
iwasherefirst2 commented 4 years ago

I think you posted this in the wrong repository. You seem to use https://github.com/spatie/laravel-translatable

ExsyDev commented 4 years ago

@iwasherefirst2 no. When I remove this middleware:

        ->middleware(['localize', 'localeCookieRedirect', 'localizationRedirect', 'localeViewPath'])

all working good.

iwasherefirst2 commented 4 years ago

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?