public function addData()
 {
     $data = $this->request()->request->all();
     $data['user_id'] = $this->request()->getSession()->get('uid');
     $id = Posts::create($data);
     return new RedirectResponse('/admin/post');
 }
 public function add()
 {
     $post = Posts::create();
     if ($this->request->data && $post->save($this->request->data)) {
         $this->redirect(array('Posts::index'));
     }
     return compact('post');
 }
 public function add()
 {
     $post = Posts::create();
     if ($this->request->data && $post->save($this->request->data)) {
         return $this->redirect(array('Posts::view', 'args' => array($post->id)));
     }
     return compact('post');
 }
 public function add()
 {
     if (!Auth::check('default')) {
         return $this->redirect('Sessions::add');
     }
     $success = false;
     if ($this->request->data) {
         $post = Posts::create($this->request->data);
         $success = $post->save();
     }
     return compact('success');
 }
 /**
  * Add member post
  *
  */
 public static function add()
 {
     if (!Request::is_authenticated()) {
         Session::push('flash-message', 'You must login before!');
         Response::redirect('login?next=post/add');
     }
     if ("POST" == Request::method()) {
         $id_member = Request::user()->id;
         $data = Request::POST()->post;
         $title = Request::POST()->title;
         $cat = Request::POST()->category;
         # $post = new Posts();
         # $post->id = $id_member;
         # $post->post = $data;
         # $post->save();
         Posts::create($id_member, $title, $data, $cat);
         Session::push('flash-message-info', 'Your post has added successfully!');
         Response::redirect('');
     } else {
         $users = Accounts::find(['type' => 2]);
         # /app/views/member/add-post.php
         View::render('member/add-post', ['users' => $users, 'categories' => Categories::all()]);
     }
 }
 public function addAction()
 {
     $success = false;
     $url = "";
     $errors = array();
     if (!Auth::check('default')) {
         $errors['login'] = '******';
     } else {
         if (!$this->request->is('post')) {
             $errors['call'] = 'This action can only be called with post';
         } else {
             if ($this->request->data) {
                 $post = Posts::create($this->request->data);
                 if ($success = $post->save()) {
                     $url = "http://" . $_SERVER['HTTP_HOST'] . Router::match(array('controller' => 'posts', 'action' => 'view', 'id' => $post->id));
                 } else {
                     $errors = $post->errors();
                 }
             }
         }
     }
     return compact('success', 'errors', 'url');
 }
 public function criarNovoPost()
 {
     $input = \Input::except('_token', 'img');
     if ($input['post_categoria_id'] == '') {
         return 'categoriavazia';
     } else {
         if ($input['post_titulo'] == '' || $input['post_conteudo'] == '') {
             return 'camposvazio';
         } else {
             // Preparando o ember do video
             if ($input['post_video'] != '') {
                 $input['post_video'] = VideoID($input['post_video']);
             }
             if (!isset($input['post_data']) || $input['post_data'] == '') {
                 $input['post_data'] = date("Y-m-d H:i:s");
                 // Data
             }
             $input['created_at'] = date("Y-m-d H:i:s");
             // Data
             $input['post_slug'] = str_slug($input['post_titulo']);
             // Preparando o slug
             // Uploads
             $file = \Input::file('img');
             if (!empty($file)) {
                 $upload = new \App\Library\UploadHelpers();
                 if ($upload->ImageUpload($file)) {
                     $input['post_capa'] = $upload->NomeArquivo();
                     // Criando o valor a ser enviado para o banco de dados com o nome e caminho do arquivo
                 }
             }
             // tags
             $tags = \Input::get('post_tags');
             if (is_array($tags) && count($tags) > 0) {
                 $input['post_tags'] = implode(",", $tags);
             }
             // Autor
             $input['post_autor'] = \Auth::user()->id;
             $create = \App\Models\Posts::create($input);
             if ($create) {
                 return 'sucesso';
             }
         }
     }
 }