本文整理匯總了PHP中app\Category::getAllFromCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::getAllFromCache方法的具體用法?PHP Category::getAllFromCache怎麽用?PHP Category::getAllFromCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Category
的用法示例。
在下文中一共展示了Category::getAllFromCache方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
if (Schema::hasTable('categories')) {
$categories = Category::getAllFromCache();
view()->share('categories', $categories);
}
}
示例2: index
public function index(Request $request = null, $alias = null, $paginate = 15)
{
$time_start = microtime(true);
$tasks = Task::where('deleted', false);
if (!empty($alias) && strlen($alias) >= 1 && strlen($alias) <= 20) {
$categories = Category::getAllFromCache();
$found_category = null;
foreach ($categories as $category) {
if ($category->alias == $alias) {
$found_category = $category;
break;
}
}
if ($found_category) {
$tasks = $tasks->where('category_id', $found_category->id);
}
}
if (!$alias) {
$alias = '';
}
$current_page = !empty($request->input('page')) ? (int) $request->input('page') : 1;
$cache_name = __METHOD__ . '_alias=' . $alias . 'paginate=' . $paginate . 'page=' . $current_page;
$tasks = Cache::remember($cache_name, Config::get('constants.CACHE_TIME_DAY'), function () use($tasks, $paginate, $cache_name) {
if (App::environment('local')) {
Log::debug('Cache: ' . $cache_name);
}
return $tasks->orderBy('created_at', 'desc')->paginate($paginate);
});
Task::resolveTasksDependencies($tasks);
$time_end = microtime(true);
return view('task/index', ['tasks' => $tasks, 'alias' => $alias, 'debug_time_of_execution' => $time_end - $time_start]);
}
示例3: resolveTaskDependencies
public static function resolveTaskDependencies(&$task, $categories = null)
{
if (!$categories) {
$categories = Category::getAllFromCache();
}
$task->category_name = $categories[$task->category_id - 1]->name;
$cache_name = __METHOD__ . '_task_id=' . $task->id;
$task->files = Cache::remember($cache_name, Config::get('constants.CACHE_TIME_DAY'), function () use($task, $cache_name) {
if (App::environment('local')) {
Log::debug('Cache: ' . $cache_name);
}
return TaskFile::where('task_id', $task->id)->where('deleted', false)->select('id', 'name', 'user_id', 'task_id', 'created_at', 'updated_at')->get();
});
$task->solutions = Solution::getTaskSolutionsDependencies($task->id);
}