我的客户正在使用laravel
版。 5.2应用。
我试图创建一个TranslationServiceProvider
。但是我的代码总是抛出此错误:
[2019-07-18 20:59:09]本地。错误: Symfony \ Component \ Debug \ Exception \ FatalThrowableError:调用 未定义的方法Illuminate \ Support \ Facades \ Cache :: remember()在 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Facades \ Facade.php:221 堆栈跟踪: 0 D:\ Files \ Company \ app \ Providers \ TranslationServiceProvider.php(53):照亮\ Support \ Facades \ Facade :: __ callStatic('remember',Array) 1 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Application.php(554): App \ Providers \ TranslationServiceProvider-> register() 2 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ ProviderRepository.php(74): Illuminate \ Foundation \ Application-> register(Object(App \ Providers \ TranslationServiceProvider)) 3 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Application.php(530): 照亮\ Foundation \ ProviderRepository-> load(Array) 4 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Bootstrap \ RegisterProviders.php(17): Illuminate \ Foundation \ Application-> registerConfiguredProviders() 5 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Application.php(203): Illuminate \ Foundation \ Bootstrap \ RegisterProviders-> bootstrap(对象(Illuminate \ Foundation \ Application)) 6 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php(232): 照亮\ Foundation \ Application-> bootstrapWith(Array) 7 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php(127): Illuminate \ Foundation \ Http \ Kernel-> bootstrap() 8 D:\ Files \ Company \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php(99): Illuminate \ Foundation \ Http \ Kernel-> sendRequestThroughRouter(Object(Illuminate \ Http \ Request)) 9 D:\ Files \ Company \ public \ index.php(53):Illuminate \ Foundation \ Http \ Kernel-> handle(Object(Illuminate \ Http \ Request)) 10 {main}
...
这是我的翻译服务提供商代码:
<?php
namespace App\Providers;
use App;
use File;
use Cache;
use Illuminate\Support\ServiceProvider;
class TranslationServiceProvider extends ServiceProvider
{
/**
* The path to the current lang files.
*
* @var string
*/
protected $langPath;
/**
* Create a new service provider instance.
*
* @return void
*/
public function __construct()
{
$this->langPath = resource_path('lang/'.App::getLocale());
}
/**
* Bootstrap the application services.
*
* @return void
*/
public function register()
{
$minutes = 24*60;
Cache::remember('translations', $minutes, function () {
return collect(File::allFiles($this->langPath))->flatMap(function ($file) {
return [
($translation = $file->getBasename('.php')) => trans($translation),
];
})->toJson();
});
}
}
方法Cache::remember()
是未定义的方法是什么原因,如何解决?
感谢所有提前提示!