I am trying to get all database values from the Configs database table into the ConfigServiceProvider, to reuse those variables in all blades throughout the site. But I keep on getting an error "Call to a member function connection() on null". Can it be that I cannot do database queries from a provider?
use Illuminate\Support\ServiceProvider;
use App\Models\Config;
class ConfigServiceProvider extends ServiceProvider {
public function register() {
$globals = Config::all();
print_r($globals);
}
}
If so, how do I do this then?
You can't do that in the 'register' method. Move it to the 'boot' method.
Specifically, you should only perform bindings in the register method, see the documentation for an in depth explanation.