找不到 Laravel 5 类“App\Http\Controllers\Cache”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29131808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Class 'App\Http\Controllers\Cache' not found
提问by oldstyle inn
When I use cache on laravel, 5 it keeps on giving me an error Class 'App\Http\Controllers\Cache' not found
当我在 laravel 上使用缓存时,5 它一直给我一个错误Class 'App\Http\Controllers\Cache' not found
<?php namespace App\Http\Controllers;
class ChannelController extends Controller {
public function popular()
{
Cache::put('test','test value',10);
}
}
It's just a simple cache but still not working. By the way, my config for cache is set to memcached - and it is working fine on laravel 4.2, but not on laravel 5.
这只是一个简单的缓存,但仍然无法正常工作。顺便说一句,我的缓存配置设置为 memcached - 它在 laravel 4.2 上运行良好,但在 laravel 5 上运行良好。
回答by NaN
Cache is not inside your App namespace, you can either:
缓存不在您的 App 命名空间内,您可以:
<?php namespace App\Http\Controllers;
use \Cache;
class ChannelController extends Controller {
You can then use Cache
throughout your class. Alternatively you can add a \
to the existing line you have:
然后,您可以Cache
在整个课程中使用。或者,您可以\
在现有的行中添加一个:
\Cache::put('test','test value',10);
回答by Kelly Kiernan
You just need to import Cache. Add this to the top of your file after the namespace declaration but before your class.
您只需要导入缓存。在命名空间声明之后但在类之前将其添加到文件顶部。
use Cache;