예제 #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);
 }
 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');
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     Nav::findOrFail($id)->delete();
     return redirect()->back();
 }