Cache facade not working in Laravel 5

I want some settings to be user-manageable. Because of this, I am storing them in database, retrieving and caching them afterwards. However, when I try to call Cache facade inside the config/config.php file, I get an error. Details are given below.

I have following code located in app/config/custom.php:

// app/config/custom.php

use IlluminateSupportFacadesCache;

return [
   'foo' => Cache::get('foo');

Which spits out a following error:

Fatal error: Call to a member function get() on a non-object in
on line 216

How to fix this?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

As discussed in the comments, config files are not meant to store dynamic application values, if it’s dynamic (i.e. User specific values), you should handle them in different parts of the application.

You can make something available globally throughout your application by using Service Providers.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x