/** * @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); }
/** * @return string */ public function getRouting() { $category = new Category($this->model->getAttribute('category_id')); $path = $category->getRouting(); return $path . '/' . $this->id; }