Пример #1
0
 public function find($id)
 {
     $model = Category::getInstance()->getOne($id);
     $model = $this->format($model);
     $model = $this->formatNumber($model);
     return $model;
 }
Пример #2
0
 public function getId($category)
 {
     if (empty($category)) {
         return 0;
     }
     $model = Category::whereRaw("name=?", [$category])->first();
     return $model ? $model->id : 0;
 }
Пример #3
0
 public function run()
 {
     $this->truncate('category');
     $data = $this->data();
     $time = time();
     array_walk($data, function (&$v) use($time) {
         $v['created_at'] = $time;
         $v['updated_at'] = $time;
     });
     Category::insert($data);
 }
Пример #4
0
 /**
  * 文章列表页面
  * @param $category
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function getList($category)
 {
     $category = Category::getInstance()->findByName($category);
     if (empty($category)) {
         return redirect('/site/index');
     }
     $articles = Article::getInstance()->findByCategory($category->id);
     $this->viewData('crumbs', $this->articleCrumbs($category));
     $this->viewData('summary', $this->articleSummary($category));
     $this->viewData('articles', $this->articleList($articles));
     $this->viewData('bodyId', 'article-container');
     $this->viewData('navMenuActive', 'article-detail');
     return view('frontend.article.category', $this->viewData);
 }
Пример #5
0
 /**
  * Store a newly created category in storage.
  * @param Create $request
  * @return Response
  */
 public function store(Create $request)
 {
     $data = $request->all();
     $category = Category::create($data);
     return redirect()->route('categories.index');
 }
Пример #6
0
 public function renderSideTree()
 {
     $str[] = '<ul>';
     $data = Category::getInstance()->getNavList();
     $tpl = '<li><a href="%s" title="%s">%s (%s)</a></li>';
     foreach ($data as $item) {
         $str[] = sprintf($tpl, '/article/' . strtolower($item->name), $item->name, $item->name, $item->article_amount);
     }
     $str[] = '</ul>';
     echo implode('', $str);
 }
Пример #7
0
 public function getNavList()
 {
     return Category::getInstance()->whereRaw('`pid`=0 AND `order` <> 0')->orderBy('order', 'ASC')->get();
 }