Ejemplo n.º 1
0
 public function update(Request $request)
 {
     $user = $request->auth;
     $id = $request->route('id');
     $uniq = md5(uniqid(time(), true));
     if ($request->hasFile('image')) {
         $types = array('115x69', '285x170', '617x324');
         // Width and height for thumb and resiged
         $sizes = array(array('115', '69'), array('285', '170'), array('617', '324'));
         $targetPath = 'img/media/';
         $image = $request->file('image');
         $ext = $image->getClientOriginalExtension();
         foreach ($types as $key => $type) {
             Image::make($image)->fit($sizes[$key][0], $sizes[$key][1])->save($targetPath . $type . "/" . $uniq . '.' . $ext);
         }
     }
     $post = PostModel::findOrFail($id);
     $post->pos_name = ucfirst($request->input('pos_name'));
     $post->pos_slug = $request->input('pos_slug');
     if ($request->hasFile('image')) {
         $post->pos_image = $uniq . '.' . $ext;
     }
     $post->pos_sum = $request->input('pos_sum');
     $post->pos_desc = $request->input('pos_desc');
     $post->pos_status_cd = "ACT";
     $post->cat_id = $request->input('cat_id');
     $post->updated_by = $user->usr_id;
     if (!$post->save()) {
         return "Error";
     }
     return Redirect::route('postHome');
 }
Ejemplo n.º 2
0
 /**
  * Return the field values from the model
  *
  * @param integer $id
  * @param array $fields
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $post = Post::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $post->{$field};
     }
     $fields['tags'] = $post->tags()->lists('tag')->all();
     return $fields;
 }
Ejemplo n.º 3
0
 /**
  * 記事削除
  */
 public function postDelete(Request $request)
 {
     $post = Post::findOrFail($request->id);
     $post->delete();
     \Session::flash('flash_message', '削除しました。');
     return redirect('/');
 }