Ejemplo n.º 1
0
 public function __construct()
 {
     $navs = Nav::orderBy('sort', 'desc')->get();
     $function = function ($closure, $navs, $pid = 0) {
         $return = null;
         foreach ($navs as $nav) {
             if ($nav->parent_id == $pid) {
                 if (null != ($children = call_user_func($closure, $closure, $navs, $nav->id))) {
                     $return[] = [$nav, $children];
                 } else {
                     $return[] = $nav;
                 }
             }
         }
         return $return;
     };
     $d = Option::all();
     $options = [];
     foreach ($d as $option) {
         $options[$option->key] = $option->value;
     }
     $collection = DB::table('articles')->select(DB::raw("DATE_FORMAT(`created_at`, '%Y %m') as `archive`, count(*) as `count`"))->where('category_id', '!=', 0)->where('display', '=', true)->orderBy('created_at', 'desc')->groupBy('archive')->get();
     view()->share('navs', $function($function, $navs));
     view()->share('categories', Category::all());
     view()->share('tags', Tag::all());
     view()->share('archive', $collection);
     view()->share('options', $options);
 }
Ejemplo n.º 2
0
 public function category($name)
 {
     if (is_numeric($name)) {
         $category = Category::with('articles')->where('id', '=', $name)->firstOrFail();
     } else {
         $category = Category::with('articles')->where('name', '=', $name)->firstOrFail();
     }
     return view('page.category')->with('category', $category)->with('articles', $category->articles()->where('display', '=', true)->orderBy('sort', 'desc')->orderBy('created_at', 'desc')->orderBy('id', 'desc')->paginate(10));
 }
 public function store()
 {
     $articles = Article::all();
     if (!is_dir('html')) {
         mkdir('html');
     }
     $navs = Nav::orderBy('sort', 'desc')->get();
     $function = function ($closure, $navs, $pid = 0) {
         $return = null;
         foreach ($navs as $nav) {
             if ($nav->parent_id == $pid) {
                 if (null != ($children = call_user_func($closure, $closure, $navs, $nav->id))) {
                     $return[] = [$nav, $children];
                 } else {
                     $return[] = $nav;
                 }
             }
         }
         return $return;
     };
     $d = Option::all();
     $options = [];
     foreach ($d as $option) {
         $options[$option->key] = $option->value;
     }
     view()->share('navs', $function($function, $navs));
     view()->share('categories', Category::all());
     view()->share('tags', Tag::all());
     view()->share('options', $options);
     view()->share('staticMode', true);
     view()->share('staticCreateTime', date('Y/m/d H:i:s', time()));
     foreach ($articles as $article) {
         if (empty($article->name)) {
             continue;
         }
         if ($article->category_id == 0) {
             $data = view('page.page')->withArticle($article)->render();
         } else {
             $data = view('page.article')->withArticle($article)->render();
         }
         file_put_contents('html/' . $article->name . '.html', $data);
     }
     return redirect('admin/article');
 }
Ejemplo n.º 4
0
 protected function traverseToDelete($parent)
 {
     $t = Category::where('parent_id', '=', $parent)->get();
     foreach ($t as $category) {
         $this->traverseToDelete($category->id);
         $category->delete();
     }
 }
Ejemplo n.º 5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function edit($id, Request $request)
 {
     $article = Article::findOrFail($id);
     $categories = Category::all();
     $tags = Tag::all();
     $tagSelect = [];
     foreach ($article->tags as $tag) {
         $tagSelect[] = $tag->id;
     }
     return view('admin.article.edit', ['categories' => $categories, 'article' => $article, 'tags' => $tags, 'tagSelect' => $tagSelect]);
 }