<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/11/12 * Time: 10:58 */ namespace App\Repositories; use App\Models\Page; use Illuminate\Support\Facades\Cache; use Prettus\Repository\Eloquent\BaseRepository; /** * Class PageRepositoryEloquent. * * @package namespace App\Repositories; */ class PageRepository extends BaseRepository { /** * Specify Model class name * * @return string */ public function model() { return Page::class; } public static function pageCache() { /* if (!config('aix.system.site_safety.subsite.close_subsite')) { $where['subsite_id'] = Cache::get('subsite_id'); } $cache = '_'.Cache::get('subsite_id');*/ $cache = ''; //$where['type'] = 'Home'; $where = array(); if (null === $pageList = Cache::get('Home_page_list'.$cache)) { $pages = Page::select('alias', 'id', 'pname', 'route', 'rewrite', 'url', 'tag', 'caching')->where($where)->get(); foreach ($pages as $key => $val) { $pageList[$val->alias] = $val; $pageList[$val->alias]->lower_route = strtolower($val->route); } Cache::forever('Home_page_list'.$cache, $pageList); } return $pageList; } public function getPage() { /*if (Cache::has('subsite_id')) { $subsite_id = Cache::get('subsite_id'); $cache = '_'.$subsite_id; } else { $subsite_id = 0; $cache = '_'; }*/ $cache = '_'; $page_seo = Cache::get('Home_page_seo_list'.$cache); if ($page_seo === null) { $page_seo = $this->pageSeoCache(/*$subsite_id*/); Cache::forever('Home_page_seo_list'.$cache, $page_seo); } return $page_seo; } public function pageSeoCache(/*$subsite_id*/) { $where = array(); /*if ($subsite_id !== false) { $where['subsite_id'] = $subsite_id; }*/ $pageList = $this->model->where($where)->get()->toArray(); $page = array(); if ($pageList) { foreach ($pageList as $key => $val) { if ($val['route']) { $page[strtolower($val['route'])] = array('title'=>$val['title'],'keywords'=>$val['keywords'],'description'=>$val['description']); } } } return $page; } }