Exemplo n.º 1
0
 /**
  * Creates a new Posts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Posts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PostRequest $request)
 {
     $post = new Posts();
     $post->title = $request->get('title');
     $post->body = $request->get('body');
     $post->slug = str_slug($post->title);
     $post->author_id = $request->user()->id;
     $post->category = $request->get('category');
     $post->tag = $request->get('post_tag');
     $v = Validator::make($request->all(), ['category' => 'required', 'title' => 'required', 'body' => 'required']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors());
     } else {
         if ($request->has('save')) {
             $post->active = 0;
             $message = 'Post saved successfully';
         } else {
             $post->active = 1;
             $message = 'Post published successfully';
         }
         if ($post->save()) {
             $p = base_path() . '/app/Modules/Blog/myupload';
             if (!is_dir($p)) {
                 mkdir($p);
                 chmod($p, 0777);
             }
             $path = base_path() . '/app/Modules/Blog/myupload/' . $post->id;
             if (!is_dir($path)) {
                 mkdir($path);
                 chmod($path, 0777);
             }
             $files = Input::file('images');
             $imagesStr = Posts::saveMedia($path, $post->id, $files, array('png', 'jpeg', 'jpg', 'gif'), 'IMG_', 'image');
             $files2 = Input::file('videos');
             $videoStr = Posts::saveMedia($path, $post->id, $files2, array('mp4', 'avi', '3gp'), 'VDO_', 'video');
             $files3 = Input::file('otherfiles');
             $OtherStr = Posts::saveMedia($path, $post->id, $files3, array('mp4', 'avi', '3gp', 'docx', 'xls', 'xlsx', 'pdf', 'jpeg', 'png'), 'OTHR_', 'other');
             return redirect('edit/' . $post->slug)->withMessage($message);
         }
     }
 }