Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating on Database error - Call to a member function translations() on null #295

Open
rivalex opened this issue Dec 20, 2023 · 3 comments

Comments

@rivalex
Copy link

rivalex commented Dec 20, 2023

I was able to integrate your solution perfectly into my App.
I integrated your solution with Laravel-Lang, so I can add/remove already partially translated languages.
I also managed to implement views so as to filter translations that have not yet been translated, mark all non translated string, completion percentage etc.

My app is published on Forge from a GIT repository.

2 problems

  1. I had to exclude the Lang folder from GIT because modifying the files in production creates a misalignment with GIT and blocks the deployment on Forge.
  2. Locally everything works perfectly but in production it seems that the system cannot write to the files. It continues to overwrite the last row of the array and does not store subsequent strings.

At this point I would like to move the translations to the database but when I change the driver from file to database I always get the same error, also migrating others tables:


Error 

  Call to a member function translations() on null

  at vendor/joedixon/laravel-translation/src/Drivers/Database.php:159
    155▕      */
    156▕     public function getSingleTranslationsFor($language)
    157▕     {
    158▕         $translations = $this->getLanguage($language)
  ➜ 159▕             ->translations()
    160▕             ->where('group', 'like', '%single')
    161▕             ->orWhereNull('group')
    162▕             ->get()
    163▕             ->groupBy('group');

      +12 vendor frames 

  13  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Rinvex\Country\Providers\CountryServiceProvider))
      +5 vendor frames 

  19  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I also tried manually creating the migrations, and creating the tables.
Everything works but if I change the driver from file to database I always get the usual error, both in the console and online.

Thanks in advance for the support

  • OS: OSX
  • Browser chrome, safari
  • Version leatest

Screenshot 2023-12-20 alle 18 42 10 Screenshot 2023-12-20 alle 18 32 49 Screenshot 2023-12-20 alle 18 33 58 Screenshot 2023-12-20 alle 18 34 21
@rivalex rivalex changed the title Migrating on Database error Migrating on Database error - Call to a member function translations() on null Dec 20, 2023
@rivalex
Copy link
Author

rivalex commented Jan 12, 2024

Hi Joedixon, by any chance, have you had time to see this error?

@rivalex
Copy link
Author

rivalex commented Jan 12, 2024

Hi Joedixon ... I find my escape room 😅

/**
     * Load the messages for the given locale.
     *
     * @param  string  $locale
     * @param  string  $group
     * @param  string  $namespace
     * @return array
     */
    public function load($locale, $group, $namespace = null)
    {
        if ($group == '*' && $namespace == '*') {
            return $this->translation->getSingleTranslationsFor($locale)->get('single', collect())->toArray();
        }

        if (is_null($namespace) || $namespace == '*') {
            return $this->translation->getGroupTranslationsFor($locale)->filter(function ($value, $key) use ($group) {
                return $key === $group;
            })->first();
        }

        return $this->translation->getGroupTranslationsFor($locale)->filter(function ($value, $key) use ($group, $namespace) {
            return $key === "{$namespace}::{$group}";
        })->first();
    }

I commented the first IF in load function in src/ContractDatabaseLoader.php file

if ($group == '*' && $namespace == '*') {
    return $this->translation->getSingleTranslationsFor($locale)->get('single', collect())->toArray();
}

All works fine ... migrations done and sync all files to DB.
Then I remove comments and now all works on DB.

Hope this feedback can help

ciao

Alessandro

@timoye
Copy link

timoye commented Jul 30, 2024

Hello @rivalex ,would you kindly raise a PR for this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants