1
我通過擴展引導方法來啓動我的Laravel
應用程序,其中我有一個檢查緩存中的值的小檢查點。對於這個我使用Laravel's
自己Illuminate\Foundation
helper function
cache
,但不幸的是我得到和錯誤,我的應用程序代碼是:如何在Laravel中使用Cache輔助函數
<?php
namespace App;
use Illuminate\Foundation\Application as IlluminateApplication;
use LayerShifter\TLDExtract\Extract;
/**
* Extends \Illuminate\Foundation\Application to override some defaults.
*/
class Application extends IlluminateApplication
{
/**
* Is Client.
*
* @var boolean
*/
protected $isClient = false;
/**
* Client secret key.
*
* @var boolean
*/
protected $clientSecret;
/**
* Client ID.
*
* @var boolean
*/
protected $clientID;
/**
* Constructing the class with tenant check
*/
public function __construct($basePath = null)
{
parent::__construct($basePath);
$this->clientCheck();
}
public function clientCheck()
{
if($this->isClient = cache('is_client'))
{
return $this->isClient;
}
else
{
$domainData = $this->getDomainSubDomain();
//Do Check and return the value,
//Set the values
// Cache for one day
$data = //Data which is being recieved
cache(['is_client' => $data], 1 * 24 * 60);
return $data;
}
}
/**
* Get Domain and Sub Domain
*
* @return array
*/
public function getDomainSubDomain()
{
$http_req = php_sapi_name() == 'cli' ? 'noetic.com' : $_SERVER["SERVER_NAME"];
$extract = new Extract();
$result = $extract->parse($http_req);
return array(
"domain" => $result->getHostname() . '.' . $result->getSuffix(),
"subDomain" => $result->getSubdomain()
);
}
}
錯誤,我越來越:
Fatal error: Uncaught ReflectionException: Class cache does not exist in
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php:729 Stack trace: #0
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(729): ReflectionClass->__construct('cache') #1
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(608): Illuminate\Container\Container->build('cache') #2
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(575): Illuminate\Container\Container->resolve('cache') #3
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(728): Illuminate\Container\Container->make('cache') #4
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(106): Illuminate\Foundation\Application->make('cache') #5
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(230): app('cache') #6
E:\ in E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 729
指引我我怎麼能做到這一點。
你試過用'app(「cache」)'? –
也許緩存服務尚未包含在內。嘗試在控制器中使用該功能,如果這可以正常工作,那麼顯然問題是應用程序尚未啓動緩存方法。 –
@ParantapParashar:緩存正在通過控制器工作,但我的問題是我想在加載應用程序之前進行緩存存儲檢查,我有不同的環境需要加載相應的不同域,FYI你可以看看在這個應用程序https://github.com/phanan/koel/blob/master/app/Application.php#L88 –