/** * Store a newly created resource in storage. * * @return Response */ public function store() { // Declare the rules for the form validation $rules = array('title' => 'required|min:3', 'content' => 'required|min:3|not_in:<p></p>', 'image' => 'image|max:30000000'); // Create a new validator instance from our validation rules $validator = Validator::make(Input::all(), $rules); // If validation fails, we'll exit the operation now. if ($validator->fails()) { // Ooops.. something went wrong return Redirect::back()->withInput()->withErrors($validator); } // Create a new blog post $post = new BlogPost(); // Update the blog post data $post->title = e(Input::get('title')); if (empty($post->slug)) { $post->slug = e(Str::slug(Input::get('title'))); } else { $post->slug = e(Str::slug(Input::get('slug'))); } $post->content = e(Input::get('content')); $post->draft = e(Input::get('draft')); $post->lang = e(Input::get('lang')); $post->content = e(Input::get('content')); $post->meta_title = e(Input::get('meta-title')); $post->meta_description = e(Input::get('meta-description')); $post->meta_keywords = e(Input::get('meta-keywords')); $post->user_id = Sentry::getId(); $image = Input::file('image'); if (!empty($image)) { $filename = $post->slug . '_' . date('d-m-Y') . '.' . $image->getClientOriginalExtension(); $uploadSuccess = Input::file('image')->move($this->destinationPath, $filename); $post->image = e($filename); } // Was the blog post created? if ($post->save()) { $tags = explode(',', Input::get('blogtags')); foreach ($tags as $tag) { if (BlogTag::where('name', '=', $tag)->count() == 0) { $newTag = new BlogTag(); $newTag->name = ucwords($tag); $newTag->slug = Str::slug($tag); $newTag->save(); } else { $newTag = BlogTag::where('name', '=', $tag)->first(); } $post->tags()->attach($newTag->id); } // Redirect to the new blog post page return Redirect::route('blog.show', array('blog' => $post->slug))->with('success', Lang::get('modules/blog/messages.success.create')); } // Redirect to the blog post create page return Redirect::route('blog.create')->with('error', Lang::get('modules/blog/messages.error.create')); }