laravel-localization icon indicating copy to clipboard operation
laravel-localization copied to clipboard

Route model binding is not work

Open ExsyDev opened this issue 4 years ago • 3 comments

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}";
      }
  }

ExsyDev avatar Jan 07 '20 19:01 ExsyDev

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

iwasherefirst2 avatar Jan 07 '20 19:01 iwasherefirst2

@iwasherefirst2 no. When I remove this middleware:

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

all working good.

ExsyDev avatar Jan 07 '20 20:01 ExsyDev

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?

iwasherefirst2 avatar Apr 24 '20 07:04 iwasherefirst2