joedixon / laravel-translation

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

"database" driver gives "Invalid argument supplied for foreach()" error on translations page #228

Closed Atif-Bashir-1998 closed 2 years ago

Atif-Bashir-1998 commented 2 years ago

Description of the bug Using the "database" driver does not translates the text on /languages page and it also gives an error of Invalid argument supplied for foreach()

To Reproduce Steps to reproduce the behavior:

  1. Create a fresh laravel project using composer
  2. Follow the steps mentioned in the documentation of this package
  3. Go to /config/translation.php file and change the 'driver' => 'file' to 'driver' => 'database',
  4. Run the project locally and visit the languages page at http://localhost:8000/languages

Expected behavior Expected behavior should be similar regardless of the type of driver

Screenshots image

image

Atif-Bashir-1998 commented 2 years ago

If anyone else is getting the same issue, the main reason that the database driver is not working is that the translations are not synced.

To solve the issue, follow these steps:

  1. After changing driver to database in config/translation.php, run php artisan migrate
  2. run the command php artisan translation:sync-translations
  3. You will be prompted a few questions. See the screenshot image