本文整理汇总了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);
}