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);
 }
 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.º 3
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $categories = Category::all();
     return view('admin.category.index', ['categories' => $categories]);
 }
Ejemplo n.º 4
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]);
 }