public function action_edit($id) { $post = \Blog\Models\Post::find($id); if ($post === null) { return Event::first('404'); } if (Str::lower(Request::method()) == "post") { $validator = Validator::make(Input::all(), self::$rules); if ($validator->passes()) { $post->title = Input::get('title'); if (Input::get('slug')) { $post->slug = Str::slug(Input::get('slug')); } else { $post->slug = Str::slug(Input::get('title')); } $post->intro = Input::get('intro'); $post->content = Input::get('content'); $post->author_id = Input::get('author_id'); $post->category_id = Input::get('category_id'); $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time'); $post->save(); return Redirect::to_action('blog::admin.post@list'); } else { return Redirect::back()->with_errors($validator)->with_input(); } } else { $categories = array(); $originalCategories = \Blog\Models\Category::all(); foreach ($originalCategories as $cat) { $categories[$cat->id] = $cat->name; } return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories); } }
/** * Detach all posts from a single category * * @param $categoryId * @return bool|mixed */ public function detachAllFromCategory($categoryId) { $category = $this->category->find($categoryId); if ($category) { $category->posts()->detach(); return true; } return false; }
public function action_edit() { $category = \Blog\Models\Category::find(Input::get('id')); $attribute = Input::get('type'); $value = Input::get('value'); if ($attribute == 'slug') { $value = Str::slug($value); } $category->{$attribute} = trim($value); $category->save(); return trim($value); }