/** * Update request rules. * * @param array $rules * * @return array */ private function updateRules(array $rules) { $rules['category'] .= '|in:' . implode(',', array_keys(Category::getSelectOptions(false))); $rules['tags'] .= '|in:' . implode(',', array_keys(Tag::getSelectOptions())); $rules['status'] .= '|in:' . implode(',', PostStatus::keys()); return $rules; }
/** * Map routes. * * @param \Illuminate\Contracts\Routing\Registrar $router */ public function map(Registrar $router) { $this->group(['prefix' => 'categories', 'as' => 'categories.'], function () { $this->get('/', ['as' => 'index', 'uses' => 'CategoriesController@index']); $this->get('trash', ['as' => 'trash', 'uses' => 'CategoriesController@trash']); $this->get('create', ['as' => 'create', 'uses' => 'CategoriesController@create']); $this->post('store', ['as' => 'store', 'uses' => 'CategoriesController@store']); $this->group(['prefix' => '{blog_category_id}'], function () { $this->get('/', ['as' => 'show', 'uses' => 'CategoriesController@show']); $this->get('edit', ['as' => 'edit', 'uses' => 'CategoriesController@edit']); $this->put('update', ['as' => 'update', 'uses' => 'CategoriesController@update']); $this->put('restore', ['as' => 'restore', 'uses' => 'CategoriesController@restore']); $this->delete('delete', ['as' => 'delete', 'uses' => 'CategoriesController@delete']); }); }); $this->bind('blog_category_id', function ($id) { return Category::withTrashed()->findOrFail($id); }); }
public function delete(Category $category) { self::onlyAjax(); $this->authorize('blog.categories.delete'); try { if ($category->trashed()) { $category->forceDelete(); } else { $category->delete(); } $message = "The category {$category->name} has been successfully deleted !"; Log::info($message, $category->toArray()); $this->notifySuccess($message, 'Category deleted !'); $ajax = ['status' => 'success', 'message' => $message]; } catch (\Exception $e) { $ajax = ['status' => 'error', 'message' => $e->getMessage()]; } return response()->json($ajax); }
/** * Edit a post. * * @param \Arcanesoft\Blog\Models\Post $post * * @return \Illuminate\View\View */ public function edit(Post $post) { $this->authorize('blog.posts.update'); $title = 'Blog - Posts'; $this->setTitle($title); $this->addBreadcrumb('Edit post'); $categories = Category::getSelectOptions(); $tags = Tag::getSelectOptions(); $statuses = PostStatus::all(); return $this->view('foundation.posts.edit', compact('post', 'categories', 'tags', 'statuses')); }