vluzrmos / laravel-language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.
108 stars 25 forks source link

Auto langs detector and cache with database #27

Closed asbiin closed 4 years ago

asbiin commented 6 years ago

Hello. When using LANG_DETECTOR_LANGUAGES = 'auto', or lang-detector.languages = 'auto', values of langs are saved in cache. That's very good! This is the case on bootstrap too, especially when database is not ready yet.

Or, if the cache is set to database - see https://laravel.com/docs/5.6/cache#driver-prerequisites - the cache table is created on migration process, i.e. php artisan migrate.

Thus, when we combine cache.default = database and lang-detector.languages = auto, migration database create this issue:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.cache' doesn't exist (SQL: select * from `cache` where `key` = laravellang-detector.supported-  
  languages limit 1)  

This happens on php artisan migrate or php artisan cache:table.

Thank you

vluzrmos commented 4 years ago

I've tried to reproduce this, but never got an error. I think if you change cache driver to "database", you should be sure that table exists:

php artisan cache:table

Note: It will create the cache table migration, if you already run it before, you shouldnt do now.

and then run:

php artisan migrate
asbiin commented 4 years ago

It's reproductable:

   Illuminate\Database\QueryException 

  SQLSTATE[HY000]: General error: 1 no such table: cache (SQL: select * from "cache" where "key" = laravel_cachelang-detector.supported-languages limit 1)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673| 

  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Vluzrmos\LanguageDetector\Providers\LanguageDetectorServiceProvider))

      +25 vendor frames 
  27  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Vluzrmos\LanguageDetector\Providers\LanguageDetectorServiceProvider))