public function find($id) { $model = Category::getInstance()->getOne($id); $model = $this->format($model); $model = $this->formatNumber($model); return $model; }
public function getId($category) { if (empty($category)) { return 0; } $model = Category::whereRaw("name=?", [$category])->first(); return $model ? $model->id : 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); }
/** * 文章列表页面 * @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); }
/** * 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'); }
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); }
public function getNavList() { return Category::getInstance()->whereRaw('`pid`=0 AND `order` <> 0')->orderBy('order', 'ASC')->get(); }