Beispiel #1
0
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Post::$rules);
     if ($validator->passes()) {
         $post = new Post();
         //$post->categories->category_id = Input::get('category_id');
         $post->title = Input::get('title');
         $post->user_id = '1';
         $post->article = Input::get('article');
         //separated header with content
         $head_article = explode('[break]', Input::get('article'));
         $post->head_article = $head_article[0];
         $post->img_banner = Input::get('img_banner');
         $post->file = Input::get('file');
         $post->enabled = Input::get('enabled') == 1 ? 1 : 0;
         $post->post_date = Carbon::createFromFormat('Y-n-d G:i:s', Input::get('post_date'));
         $post->save();
         foreach (Input::get('category_id') as $category_id) {
             $post->categories()->attach(array($category_id));
         }
         //multiple select input on many to many
         return Redirect::to('blog/admin/posts/index')->with('message', 'Post Created' . Input::get('post_date'));
     }
     return Redirect::to('blog/admin/posts/new')->with('message', 'Something wrong')->withErrors($validator)->withInput();
 }