Support the ongoing development of Laravel.io →
Configuration

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,
 . . .
Last updated 2 years ago.
0

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);
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.