我想使用父构造来调用一次变量
class Home extends Controller {
public function __construct(){
$expiresAt = 10;
}
public function index() {
$data = Cache::remember('table', $expiresAt, function() {
return DB::table('table')
->ORDERBY('date', 'DESC')
->WHERE('status', 1)
->paginate(8);
});
return view('frontend.pages.home', compact('title', 'meta', 'description', 'all_resto'));
}
}
我有这个回答“Undefined variable:expiresAt”问题出在哪里
class Home extends Controller {
public $expiresAt;
public function __construct(){
$this->expiresAt = 10; // change over here.
}
public function index() {
$data = Cache::remember('table', $expiresAt, function() {
return DB::table('table')
->ORDERBY('date', 'DESC')
->WHERE('status', 1)
->paginate(8);
});
return view('frontend.pages.home', compact('title', 'meta', 'description', 'all_resto'));
}
}
旁注:在扩展Home
类的类中,您可以使用$expiresAt
变量
$this->expiresAt