/** * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse */ public function create(Request $request) { if (Category::whereEnabled(true)->whereId($request->input('category'))->count()) { $category = Category::whereEnabled(true)->whereId($request->input('category'))->firstOrFail(); $this->share('category', $category); return $this->view($category->getArticleTemplate('create')); } else { return $this->redirect->to('admin/category'); } }
/** * @return static */ public function getRelationCategoryList() { $list = Collection::make(); if ($this->model->hasParent()) { $data = $this->model->whereEnabled(true)->whereParentId($this->model->getAttribute('parent_id'))->orderBy('created_at', 'asc')->get(); } else { $data = $this->model->whereEnabled(true)->whereParentId($this->model->getAttribute('id'))->orderBy('created_at', 'asc')->get(); } if ($data->count()) { foreach ($data as $category) { $list->push(new Category($category->getAttribute('id'))); } } else { $list->push(new Category($this->model->getAttribute('id'))); } return $list; }
/** * @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); }