joedixon / laravel-translation

Translation management for your Laravel application.
MIT License
698 stars 231 forks source link

Database::getLanguage caching results, handling non existing database table #242

Closed levu42 closed 2 years ago

levu42 commented 2 years ago

This change does two things in Drivers\Database::getTranslation():

  1. Caching results for a significant reduction in amount of duplicate queries executed
  2. Handling the case where the database tables don't exist

The case where the database tables don't exist can happen when you install both laravel-translation and some other package in the same Laravel project, and the other project using translations in their service provider's boot method. In that case, when you install the project from scratch, you can't execute php artisan migrate because the other package tries accessing translations before the database can be initialized, and so far we're relying on the database to be set up for us to work. The fix here is to just handle non-existing database tables for translation as "this language doesn't exist in the database", allowing the migrations to run.