/**
  * Store a newly created resource in storage.
  * @return Response
  */
 public function store()
 {
     $post = new posts();
     $post->idpengguna = Auth::user()->id;
     $post->judul = Input::get('judul');
     $post->isi = Input::get('isi');
     $post->tag = Input::get('tag');
     $post->slug = str_slug(input::get('judul'));
     if (Input::hasfile('sampul')) {
         $sampul = date("YmdHis") . uniqid() . "." . Input::file('sampul')->getClientOriginalExtension();
         Input::file('sampul')->move(storage_path(), $sampul);
         $post->sampul = $sampul;
     }
     $post->save();
     return redirect(url('artikel'));
 }
Exemple #2
0
 public function action_add($draft = false)
 {
     try {
         if ($draft) {
             //это внутренний вызов.
             //просто создаем пустой пост
             $post = new posts(array('uid' => $this->_uid, 'status' => 'draft'));
             $post->save();
             return $post->id;
         }
         if (empty($_REQUEST['post_id']) || !is_numeric($_REQUEST['post_id']) && $_REQUEST['post_id'] !== 'new') {
             throw new Exception('Неверные параметры.');
         }
         if (!$this->_uid) {
             throw new Exception('Публиковать сообщения могут только авторизованые пользователи.');
         }
         $post_id = $_REQUEST['post_id'];
         $text = $_REQUEST['text'];
         if ($post_id === 'new' && $text === '') {
             throw new Exception('Нельзя опубликовать пустые сообщения. Напишите текст сообщения и/или прикрепите к нему вложения.');
         }
         if ($post_id === 'new') {
             $post = new posts(array('uid' => $this->_uid, 'text' => $text, 'status' => 'active'));
             $post->save();
             //вернем новый пост
             $this->action_get($post->id);
             return;
         }
         $post = posts::find_by_id($post_id);
         if (!$post) {
             throw new Exception('Сообщение не найдено.');
         }
         $post->text = $text;
         $post->status = 'active';
         $post->save();
         //вернем новый пост
         $this->action_get($post->id);
     } catch (Exception $e) {
         $this->_actions_data['_errors'][] = $e->getMessage();
         $this->_actions_data['_ok'] = 0;
         return 0;
     }
 }