gpt4 book ai didi

Laravel 错误:调用未定义的方法 Illuminate\Support\Facades\Cache::rememberForever()

转载 作者:行者123 更新时间:2023-12-05 01:28:59 25 4
gpt4 key购买 nike

我收到以下错误,我不知道为什么 rememberForever 未定义。

以下是我看到的几个常见错误跟踪:

Error {#4701
#message: "Call to undefined method Illuminate\Support\Facades\Cache::rememberForever()"
#code: 0
#file: "D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php"
#line: 261
trace: {
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:261 {
Illuminate\Support\Facades\Facade::__callStatic($method, $args) …

› return $instance->$method(...$args);
› }
}
D:\CustomDomains\HolidayBuilders\app\Providers\ComposerServiceProvider.php:120 {
App\Providers\ComposerServiceProvider->App\Providers\{closure} …
› return Spotlight::where('homepage', true)->limit(3)->get();\r
› });\r
› \r
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:381 {
Illuminate\Events\Dispatcher->Illuminate\Events\{closure} …

› return $listener(...array_values($payload));
› };
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:226 {
Illuminate\Events\Dispatcher->dispatch($event, $payload = [], $halt = false) …
› foreach ($this->getListeners($event) as $listener) {
› $response = $listener($event, $payload);

}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\Concerns\ManagesEvents.php:177 {
Illuminate\View\Factory->callComposer(View $view) …
› {
› $this->events->dispatch('composing: '.$view->name(), [$view]);
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\View.php:120 {
Illuminate\View\View->renderContents() …

› $this->factory->callComposer($this);

}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\View.php:91 {
Illuminate\View\View->render(callable $callback = null) …
› try {
› $contents = $this->renderContents();

}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Http\Response.php:62 {
Illuminate\Http\Response->setContent($content) …
› elseif ($content instanceof Renderable) {
› $content = $content->render();
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Http\Response.php:34 {
Illuminate\Http\Response->__construct($content = '', $status = 200, array $headers = []) …

› $this->setContent($content);
› $this->setStatusCode($status);
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Routing\ResponseFactory.php:55 {
Illuminate\Routing\ResponseFactory->make($content = '', $status = 200, array $headers = []) …
› {
› return new Response($content, $status, $headers);
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Routing\ResponseFactory.php:85 {
Illuminate\Routing\ResponseFactory->view($view, $data = [], $status = 200, array $headers = []) …

› return $this->make($this->view->make($view, $data), $status, $headers);
› }
}
D:\CustomDomains\HolidayBuilders\app\Exceptions\Handler.php:65 {
App\Exceptions\Handler->render($request, Throwable $exception) …
› if ($this->shouldReport($exception)) {\r
› return response()->view('errors.500', [], 500);\r
› }\r
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:51 {
Illuminate\Routing\Pipeline->handleException($passable, Throwable $e) …

› $response = $handler->render($passable, $e);

}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:172 {
Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure} …
› } catch (Throwable $e) {
› return $this->handleException($passable, $e);
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:103 {
Illuminate\Pipeline\Pipeline->then(Closure $destination) …

› return $pipeline($this->passable);
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:140 {
Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter($request) …
› ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
› ->then($this->dispatchToRouter());
› }
}
D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:109 {
Illuminate\Foundation\Http\Kernel->handle($request) …

› $response = $this->sendRequestThroughRouter($request);
› } catch (Throwable $e) {
}
D:\CustomDomains\HolidayBuilders\public\index.php:57 {
› $response = $kernel->handle(\r
› $request = Illuminate\Http\Request::capture()\r
› );\r
}
}
}

第二个共同踪迹:

Symfony\Component\ErrorHandler\Error\FatalError {#44
-error: array:4 [
"type" => 1
"message" => """
Uncaught Error: Call to undefined method Illuminate\Support\Facades\Cache::rememberForever() in D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:261\n
Stack trace:\n
#0 D:\CustomDomains\HolidayBuilders\app\Providers\ComposerServiceProvider.php(120): Illuminate\Support\Facades\Facade::__callStatic()\n
#1 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(381): App\Providers\ComposerServiceProvider->App\Providers\{closure}()\n
#2 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(226): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}()\n
#3 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\Concerns\ManagesEvents.php(177): Illuminate\Events\Dispatcher->dispatch()\n
#4 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\View.php(120): Illuminate\View\Factory->callComposer()\n
#5 D:\CustomDomains\HolidayBuilders\vendor\laravel\fr
"""
"file" => "D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php"
"line" => 261
]
#message: """
Uncaught Error: Call to undefined method Illuminate\Support\Facades\Cache::rememberForever() in D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:261\n
Stack trace:\n
#0 D:\CustomDomains\HolidayBuilders\app\Providers\ComposerServiceProvider.php(120): Illuminate\Support\Facades\Facade::__callStatic()\n
#1 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(381): App\Providers\ComposerServiceProvider->App\Providers\{closure}()\n
#2 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(226): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}()\n
#3 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\Concerns\ManagesEvents.php(177): Illuminate\Events\Dispatcher->dispatch()\n
#4 D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\View\View.php(120): Illuminate\View\Factory->callComposer()\n
#5 D:\CustomDomains\HolidayBuilders\vendor\laravel\fr
"""
#code: 0
#file: "D:\CustomDomains\HolidayBuilders\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php"
#line: 261
}

这是我的 ComposerServiceProvider@boot 方法中的代码:

    view()->composer([
'welcome',
'web.metropolitan-detail',
'web.city-detail',
'web.community-detail',
'web.community-detail-parent',
'web.inventory-detail',
'web.move-in-ready',
'web.communities',
'web.search',
'errors.500'
], function ($view) {
$view->with([
'spotlights' => Cache::rememberForever('spotlights', function () {
return Spotlight::where('homepage', true)->limit(3)->get();
}),
'testimonials' => Cache::rememberForever('testimonials', function () {
return Testimonial::limit(3)->get();
}),
]);
});

我正在使用 Laravel 7。如果我可以提供任何其他信息,请告诉我。

最佳答案

有时您需要使用composer 来重建加载到项目中的供应商类的缓存。要完成此尝试,请使用:

composer dump-autoload

他们:

php artisan optimize && php artisan cache:clear

关于Laravel 错误:调用未定义的方法 Illuminate\Support\Facades\Cache::rememberForever(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68106648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com