public function order($id) { $image = ArticleImage::findOrFail($id); $order = $image->order; $image->order = \Input::get('order'); $image->save(); if ($order > $image->order) { $images = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->orderBy('order', 'asc')->orderBy('updated_at', 'desc')->get(); } else { $images = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->orderBy('order', 'asc')->orderBy('updated_at', 'asc')->get(); } $i = 1; foreach ($images as $image) { $image->order = $i; $i++; $image->save(); } \Session::flash('message', 'Article Image order successfully updated!'); return \Redirect::back(); }