Torann / laravel-currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
http://lyften.com/projects/laravel-currency
BSD 2-Clause "Simplified" License
392 stars 137 forks source link

Table doesn't exist on installing #33

Closed ricardobarantini closed 7 years ago

ricardobarantini commented 8 years ago

After this: php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"

I receive this:

[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist (SQL: select * from `currencies`)

[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist 
abishekrsrikaanth commented 8 years ago

:+1: same issue

nigelmst commented 8 years ago

+1

0s1r1s commented 8 years ago

Just change 'driver' => 'database', to 'driver' => 'filesystem', in src/config/currency.php.

Then everything works fine. I created a pull request.

nigelmst commented 8 years ago

Unfortunately that is not a solution for users who are using database as the driver.

0s1r1s commented 8 years ago

Why not, you can change it afterwards. It's just the bundles default config.

nigelmst commented 8 years ago

Yes that is only a fix for someone who freshly installed the package, did the migration and publish the config for override.

When it comes to deployment to production that where it will start breaking and artisan will crash as well.

Doing testing will not work if a testing DB is generated from the migrations.

0s1r1s commented 8 years ago

You're right. The Problem is the getCacheCurrencies() function which is calling the all method of the driver.

A simple if ($this->database->hasTable($table)) would solve the issue. But I don't know the code of this bundle so @Torann should decide ^^.

nigelmst commented 8 years ago

Indeed!

As a temporary fix I am overriding the getCacheCurrencies and have the below condition:

    if ((App::runningInConsole() && ! App::runningUnitTests()) || (App::runningUnitTests() && !Schema::hasTable('currencies'))) {
        return ...
    }
    return parent::getCacheCurrencies();
umbertix commented 8 years ago

+1

umbertix commented 8 years ago

I've just wrote a couple line to prevent the code to crash. I would like to know what you guys think, specially @Torann , I leave the full function, even though I only have added the first block of if.

public function getCacheCurrencies()
{
    if(is_a($this->getDriver(), 'Torann\Currency\Drivers\Database')){
        $table_name = $this->getConfig('table', 'currencies');

        if(!Schema::hasTable($table_name)) {
            return $this->currencies;
        }
    }

    if (config('app.debug', false) === true) {
        return $this->currencies = $this->getDriver()
                                        ->all();
    }

    return $this->currencies = $this->cache->rememberForever('torann.currency', function () {
        return $this->getDriver()
                    ->all();
    });
}
umbertix commented 8 years ago

The bit of code that I proposed it doesn't seem to be good enought. It's throwing a new set of errors. Anyone has any update on this issue?

sebestenyb commented 8 years ago

+1

Mahmoudz commented 8 years ago

same problem till now!

Torann commented 8 years ago

I'm looking into this now. From what I remember I ran into this problem with another project I had and fixed it.

Torann commented 8 years ago

I just released a new version. http://lyften.com/projects/laravel-currency/doc/upgrade.html

It uses a middleware to handle currency switching so the database isn't trying to be called when the app boots.

Torann commented 7 years ago

Anymore problems with this? Just reopen and I'll look it over.

kikky7 commented 3 years ago

I removed my database, so it's completely empty now and I can't even run artisan commands with message 1146 Table dbname.currencies doesn't exist (SQL: select * from currencies).

Version 1.1.0