/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $rules = array('title' => 'required', 'description' => 'required'); $validator = \Validator::make(\Input::all(), $rules); // process the login if ($validator->fails()) { return \Redirect::to('blog/create')->withErrors($validator)->withTitle(\Input::get('title')); } else { // store $blog = new Blogs(); $blog->title = \Input::get('title'); $blog->description = \Input::get('description'); $blog->save(); // redirect \Session::flash('message', 'Successfully created blog!'); return \Redirect::to('blog'); } }
public function updateRecords() { $id = Request::input('id'); $title = Request::input('title'); $body = Request::input('body'); $record = Blogs::find($id); $record->title = $title; $record->body = $body; $result = $record->save(); echo $result; }
/** * ให้ค่า instance ของ model ที่ระบุด้วย entity type และ $refId * @param int $type * @param int $refId * @return ActiveRecord */ public static function getInstance($type, $refId, $orderNo = NULL) { $instance = null; switch ($type) { case self::TYPE_ACTIVITY: $instance = Activity::findOne($refId); break; case self::TYPE_BLOG: $instance = Blogs::findOne($refId); break; case self::TYPE_CARTOON: $arr = preg_split('/-/', $refId); $instance = CartoonChapter::findOne(array('cartoonId' => $arr[0], 'chapter' => $arr[1])); break; case self::TYPE_CONTENT: $instance = Content::findOne($refId); break; case self::TYPE_DOCUMENT: $instance = Document::findOne(array('type' => $type, 'refId' => $refId, 'itemNo' => $orderNo)); break; case self::TYPE_FAQ: $instance = Faq::findOne($refId); break; case self::TYPE_FEEDCONTENT: $instance = FeedContent::findOne($refId); break; case self::TYPE_FEED: $instance = Feed::findOne($refId); break; case self::TYPE_GALLERY: $instance = Gallery::findOne($refId); break; case self::TYPE_INFOGRAPHIC: $instance = InfoGraphic::findOne($refId); break; case self::TYPE_LIVEREPORT: $instance = LiveReport::findOne($refId); break; case self::TYPE_LOTTERY: $instance = Lottery::findOne($refId); break; case self::TYPE_BUNNY: case self::TYPE_MEDIA_COLLECTION: $instance = MediaCollection::findOne($refId); break; case self::TYPE_NEWSPAPER: // temporary class for media upload $instance = new stdClass(); $instance->createTime = date('Y-m-d H:i:s'); break; case self::TYPE_NOVEL: $instance = Novel::findOne($refId); break; case self::TYPE_PERSON: $instance = Person::findOne($refId); break; case self::TYPE_SPORT_PLAYER: $instance = Player::findOne($refId); break; case self::TYPE_SPORT_TEAM: $instance = Team::findOne($refId); break; case self::TYPE_QUOTE: $instance = Quote::findOne($refId); break; case self::TYPE_WIDGET: $instance = Widget::findOne($refId); break; case self::TYPE_TV_ANCHOR: $instance = TvAnchor::findOne($refId); break; case self::TYPE_TV_PROGRAM: $instance = TvProgram::findOne($refId); break; case self::TYPE_TV_HIGHLIGHT: $instance = TvHighlight::findOne($refId); break; case self::TYPE_TV_SCHEDULE: $instance = TvSchedule::findOne($refId); break; case self::TYPE_USER: $instance = User::findOne($refId); break; case self::TYPE_VIDEO: $instance = Video::findOne($refId); break; case self::TYPE_VIDEO_PLAYLIST: $instance = VideoPlaylist::findOne($refId); break; case self::TYPE_WATCHTOPIC: $instance = WatchTopic::findOne($refId); break; case self::TYPE_WEATHER: $instance = WeatherForecast::findOne($refId); break; } return $instance; }
public function blogcatEdit($id) { if (Request::isMethod('post')) { $data = Input::except(array('_token')); DB::table('blogcategories')->where('id', $id)->update($data); Session::flash('message', 'The Blog category has been updated successfully.'); Session::flash('alert-class', 'alert-success'); return Redirect::to('admin/blogcat/edit/' . $id); } $blogcatData = Blogs::findblogcatdata($id); foreach ($blogcatData as $bdata) { $blogcat = $bdata; } return View::make('admin.blogcatEdit')->with('blogcat', $blogcat); }