/**
  * @return void
  */
 public function boot()
 {
     $this->getEvents()->listen('router.before', function () {
         $categories = CategoryModel::whereEnabled(true)->get();
         foreach ($categories as $value) {
             if ($value->alias) {
                 $category = new Category($value->id);
                 $this->getRouter()->get($category->getRouting() . '/{id}', 'Notadd\\Article\\Controllers\\ArticleController@show')->where('id', '[0-9]+');
                 $this->getRouter()->get($category->getRouting(), function () use($category) {
                     return $this->app->call('Notadd\\Category\\Controllers\\CategoryController@show', ['id' => $category->getId()]);
                 });
             }
         }
     });
     $this->getRouter()->group(['namespace' => 'Notadd\\Category\\Controllers'], function () {
         $this->getRouter()->group(['middleware' => 'auth.admin', 'namespace' => 'Admin', 'prefix' => 'admin'], function () {
             $this->getRouter()->resource('category', 'CategoryController');
             $this->getRouter()->post('category/{id}/status', 'CategoryController@status');
         });
         $this->getRouter()->resource('category', 'CategoryController');
     });
     $this->getEvents()->subscribe(BeforeCategoryDelete::class);
 }
Example #2
0
 /**
  * @return mixed
  */
 public function getType()
 {
     return $this->model->getAttribute('type');
 }
 /**
  * @param $template
  */
 public function setCategoryShowTemplate($template)
 {
     $this->category->setShowTemplate($template);
 }
 /**
  * @param \Notadd\Category\Requests\CategoryEditRequest $request
  * @param $id
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function update(CategoryEditRequest $request, $id)
 {
     $category = Category::findOrFail($id);
     if ($category->update($request->all())) {
         return $this->redirect->back();
     } else {
         return $this->redirect->back()->withInput()->withErrors('保存失败!');
     }
 }
 /**
  * @param $id
  * @return \Illuminate\Contracts\View\View
  */
 public function show($id)
 {
     $crumb = [];
     Category::buildCrumb($id, $crumb);
     $articles = Article::with('category')->whereCategoryId($id)->orderBy('created_at', 'desc')->paginate(30);
     $articles->setPath($this->app->make('request')->url());
     $this->share('articles', $articles);
     $this->share('category_id', $id);
     $this->share('crumbs', $crumb);
     $this->share('count', Article::count());
     return $this->view('admin::content.article.list');
 }
Example #6
0
 /**
  * @return bool
  */
 public function isCurrentRoute()
 {
     if (strpos($this->attributes['link'], 'http://') === false && strpos($this->attributes['link'], 'https://') === false) {
         if (strpos($this->attributes['link'], 'category') !== false) {
             $tmp = trim($this->attributes['link'], '/');
             $tmp = explode('/', $tmp);
             if (is_numeric($tmp[1])) {
                 $id = $tmp[1];
                 $collection = Collection::make();
                 $ids = [];
                 if (Container::getInstance()->make('request')->route("article")) {
                     $article = Article::find(Container::getInstance()->make('request')->route("article"));
                     if ($article instanceof Article) {
                         Category::getAllParentCategories($article->category->id, $collection);
                     }
                     foreach ($collection as $category) {
                         $ids[] = $category->id;
                     }
                     $ids = array_unique($ids);
                     if (in_array($id, $ids)) {
                         return true;
                     }
                 } else {
                     Category::getAllSubCategories($id, $collection);
                     $ids[] = $id;
                     foreach ($collection as $category) {
                         $ids[] = $category->id;
                     }
                     $ids = array_unique($ids);
                     $current = Container::getInstance()->make('request')->route("category");
                     if (in_array($current, $ids)) {
                         return true;
                     }
                 }
             }
         } else {
             return Container::getInstance()->make('request')->is($this->attributes['link'] . '*') ? true : false;
         }
     }
 }