I am using the same codebase to spin up different sites which may exist in different timezones. The default place to set the timezone is in the config/app.php file in L 5.1.
So I am trying to include the model and pluck the timezone field from the DB but I get the following error:
Fatal error: Call to a member function connection() on a non-object in /var/www/my_project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 3224
In app.php I have:
use App\Models\Company;
$timeZone = Company::where('id', COMPANY_ID)->pluck('time_zone');
return [
. . .
'timezone' => $timeZone,
. . .
I would probably override this in the constructor of your controller rather than hack the config file (your db connection isn't available at that point of code execution):
$timeZone = \Company::where('id', COMPANY_ID)->pluck('time_zone');
\Config::set('app.timezone', $timeZone);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community