public function postStore() { $sid = \Input::get('id'); $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'title' => 'required|regex:/^[a-z,0-9 ._\\(\\)-?]+$/i', 'slug' => 'required|regex:/^[a-z,0-9 ._\\(\\)-?]+$/i', 'content' => 'required'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->fails()) { return redirect('admin/pages/' . (isset($sid) ? 'edit/' . $sid : 'create'))->withErrors($validation)->withInput(); } $title = \Input::get('title'); $slug = \Input::get('slug'); $content = \Input::get('content'); $image = \Input::file('image'); $private = \Input::get('private') == '' ? false : true; $category_id = \Input::get('category_id'); $tags = \Input::get('tags'); $page = isset($sid) ? Page::find($sid) : new Page(); if ($page == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The page cannot be found because it does not exist or may have been deleted."); return redirect('/admin/pages')->withErrors($errors); } $page->title = $title; $page->slug = str_replace(' ', '_', $slug); // Replace all space with underscore $page->content = $content; $page->private = $private; if ($category_id) { $page->category_id = $category_id; } else { $page->category_id = null; } $page->save(); // Save translations $translations = \Config::get('redminportal::translation'); foreach ($translations as $translation) { $lang = $translation['lang']; if ($lang == 'en') { continue; } $translated_content = array('title' => \Input::get($lang . '_title'), 'slug' => str_replace(' ', '_', \Input::get($lang . '_slug')), 'content' => \Input::get($lang . '_content')); // Check if lang exist $translated_model = $page->translations->where('lang', $lang)->first(); if ($translated_model == null) { $translated_model = new Translation(); } $translated_model->lang = $lang; $translated_model->content = json_encode($translated_content); $page->translations()->save($translated_model); } if (\Input::hasFile('image')) { //Upload the file $helper_image = new RImage(); $filename = $helper_image->upload($image, 'pages/' . $page->id, true); if ($filename) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $page->images()->save($newimage); } } if (!empty($tags)) { // Delete old tags $page->tags()->detach(); // Save tags foreach (explode(',', $tags) as $tagName) { Tag::addTag($page, $tagName); } } return redirect('admin/pages'); }
public function getDelete($sid) { // Find the page using the user id $page = Page::find($sid); if ($page == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The data cannot be deleted at this time."); return redirect('/admin/pages')->withErrors($errors); } // Delete the page $page->delete(); return redirect('admin/pages'); }