/** * This function it will analyse the new data with the old one and check what it will be updated in the defined article */ public function post_edit() { $id = Input::get('id'); $olddata = Article::find($id); $post_title = Input::get('title'); $post_body = Input::get('post_body'); $slug = Str::slug(Input::get('title')); $edit_info = array(); if (strcmp($olddata->title, $post_title) != 0) { $edit_info["title"] = $post_title; } if (strcmp($olddata->post_body, $post_body) != 0) { $edit_info["post_body"] = $post_body; } if (strcmp($olddata->slug, $slug) != 0) { $edit_info["slug"] = $slug; } $rules = array('cover' => 'image', 'slug' => 'unique:articles', 'title' => 'unique:articles|min:3|max:255'); $validation = Validator::make($edit_info, $rules); if ($validation->fails()) { return Redirect::to_route('dojo::edit_article', $id)->with_errors($validation); } else { Article::update($id, $edit_info); return Redirect::to_route('dojo::index_article'); } }
public static function post_update($field, $value, $id) { $article = Article::find($id); $article->{$field} = $value; $article->save(); }