Пример #1
0
 public function find($id)
 {
     if ($model = $this->model->find($id)) {
         $this->model = $model;
         return $this;
     }
     return null;
 }
Пример #2
0
 public function checkGroupEditable($groupid, $userid)
 {
     $group = $this->model->find($groupid);
     $moderators = $group->moderators()->lists('user_id');
     if (in_array($userid, $moderators)) {
         return true;
     }
     return false;
 }
 /**
  * 资源编辑动作
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // 获取所有表单数据.
     $data = Input::all();
     // 创建验证规则
     $rules = array('title' => 'required|' . $this->unique('title', $id), 'slug' => 'required|' . $this->unique('slug', $id), 'content' => 'required', 'category' => 'exists:article_categories,id');
     // 自定义验证消息
     $messages = $this->validatorMessages;
     // 开始验证
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // 验证成功
         // 更新资源
         $model = $this->model->find($id);
         $model->category_id = $data['category'];
         $model->title = e($data['title']);
         $model->slug = e($data['slug']);
         $model->content = e($data['content']);
         $model->meta_title = e($data['meta_title']);
         $model->meta_description = e($data['meta_description']);
         $model->meta_keywords = e($data['meta_keywords']);
         if ($model->save()) {
             // 更新成功
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // 更新失败
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // 验证失败
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
 /**
  * 资源编辑动作
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // 获取所有表单数据.
     $data = Input::all();
     // 创建验证规则
     $rules = array('email' => 'required|email|' . $this->unique('email', $id), 'password' => 'alpha_dash|between:6,16|confirmed', 'is_admin' => 'in:1');
     // 自定义验证消息
     $messages = $this->validatorMessages;
     // 开始验证
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // 验证成功
         // 更新资源
         $model = $this->model->find($id);
         $model->email = Input::get('email');
         $model->is_admin = (int) Input::get('is_admin', 0);
         if ($model->save()) {
             // 更新成功
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // 更新失败
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // 验证失败
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
Пример #5
0
 /**
  * Resource edit action
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // Get all form data.
     $data = Input::all();
     // Create validation rules
     $rules = array('email' => 'required|email|' . $this->unique('email', $id), 'password' => 'alpha_dash|between:6,16|confirmed', 'is_admin' => 'in:1');
     // Custom validation message
     $messages = $this->validatorMessages;
     // Begin verification
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // Verification success
         // Update resource
         $model = $this->model->find($id);
         $model->password = Input::get('password');
         $model->email = Input::get('email');
         $model->is_admin = (int) Input::get('is_admin', 0);
         if ($model->save()) {
             // Update success
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // Update fail
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // Verification fail
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
Пример #6
0
 /**
  * Action: Add resource images
  * @return Response
  */
 public function postUpload($id)
 {
     $input = Input::all();
     $rules = array('file' => 'image|max:3000');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $file = Input::file('file');
     $destinationPath = 'uploads/travel/';
     $ext = $file->guessClientExtension();
     // Get real extension according to mime type
     $fullname = $file->getClientOriginalName();
     // Client file name, including the extension of the client
     $hashname = date('H.i.s') . '-' . md5($fullname) . '.' . $ext;
     // Hash processed file name, including the real extension
     $picture = Image::make($file->getRealPath());
     // crop the best fitting ratio and resize image
     $picture->fit(1024, 683)->save(public_path($destinationPath . $hashname));
     $picture->fit(430, 645)->save(public_path('uploads/travel_small_thumbnails/' . $hashname));
     $picture->fit(585, 1086)->save(public_path('uploads/travel_large_thumbnails/' . $hashname));
     $model = $this->model->find($id);
     $oldThumbnails = $model->thumbnails;
     $model->thumbnails = $hashname;
     File::delete(public_path('uploads/travel_small_thumbnails/' . $oldThumbnails), public_path('uploads/travel_large_thumbnails/' . $oldThumbnails));
     $models = new TravelPictures();
     $models->filename = $hashname;
     $models->travel_id = $id;
     $models->user_id = Auth::user()->id;
     if ($model->save() && $models->save()) {
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
 }
 /**
  * Resource edit action
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // Get all form data.
     $data = Input::all();
     // Create validation rules
     $rules = array('name' => 'required|' . $this->unique('name', $id), 'sort_order' => 'required|integer');
     // Custom validation message
     $messages = $this->validatorMessages;
     // Begin verification
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // Verification success
         // Update resource
         $model = $this->model->find($id);
         $model->name = e($data['name']);
         $model->sort_order = e($data['sort_order']);
         if ($model->save()) {
             // Update success
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // Update fail
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // Verification fail
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
 /**
  * 资源编辑动作
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // 获取所有表单数据.
     $data = Input::all();
     // 创建验证规则
     $rules = array('name' => 'required|' . $this->unique('name', $id), 'sort_order' => 'required|integer');
     // 自定义验证消息
     $messages = $this->validatorMessages;
     // 开始验证
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // 验证成功
         // 更新资源
         $model = $this->model->find($id);
         $model->name = e($data['name']);
         $model->sort_order = e($data['sort_order']);
         if ($model->save()) {
             // 更新成功
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // 更新失败
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // 验证失败
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
Пример #9
0
 /**
  * Resource edit action
  * PUT/PATCH   /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // Get all form data.
     $data = Input::all();
     // Create validation rules
     $rules = array('title' => 'required|' . $this->unique('title', $id), 'slug' => 'required|' . $this->unique('slug', $id), 'content' => 'required', 'excerpt' => 'required', 'category' => 'exists:article_categories,id');
     // Custom validation message
     $messages = $this->validatorMessages;
     // Begin verification
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // Verification success
         // Update source
         $model = $this->model->find($id);
         $model->category_id = $data['category'];
         $model->title = e($data['title']);
         $model->slug = e($data['slug']);
         $model->article_icon = e($data['article_icon']);
         $model->content = e($data['content']);
         $model->excerpt = e($data['excerpt']);
         $model->meta_title = e($data['meta_title']);
         $model->meta_description = e($data['meta_description']);
         $model->meta_keywords = e($data['meta_keywords']);
         if ($model->save()) {
             // Update success
             return Redirect::back()->with('success', '<strong>' . $this->resourceName . '更新成功:</strong>您可以继续编辑' . $this->resourceName . ',或返回' . $this->resourceName . '列表。');
         } else {
             // Update fail
             return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '更新失败。</strong>');
         }
     } else {
         // Verification fail
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
 /**
  * Action: Customer checkout order
  * @return Response
  */
 public function checkout()
 {
     if (Input::get('id')) {
         $product_order = $this->model->find(Input::get('id'));
         $product_order->is_checkout = true;
         $product_order->save();
         return Redirect::back()->with('success', '确认收货成功!欢迎再次使用时光碎片尚品汇购物。');
     } else {
         return Redirect::back()->with('error', '确认收货失败,请重新尝试。');
     }
 }
Пример #11
0
 /**
  * Resource destory action
  * DELETE      /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $data = $this->model->find($id);
     if (is_null($data)) {
         return Redirect::back()->with('error', '没有找到对应的' . $this->resourceName . '。');
     } elseif ($data->delete()) {
         return Redirect::back()->with('success', $this->resourceName . '删除成功。');
     } else {
         return Redirect::back()->with('warning', $this->resourceName . '删除失败。');
     }
 }
Пример #12
0
 public function destroy($id)
 {
     if ($this->readOnly) {
         return $this->response->build(['error' => 'method_not_allowed'], SymfonyResponse::HTTP_METHOD_NOT_ALLOWED);
     }
     $entity = $this->model->find($id);
     if (!$entity) {
         return $this->response->build(['error' => 'not_found'], SymfonyResponse::HTTP_NOT_FOUND);
     }
     $entity->delete();
     return $this->response->build(null, SymfonyResponse::HTTP_NO_CONTENT);
 }
 /**
  * Action: Delete resource images
  * @return Response
  */
 public function deleteUpload($id)
 {
     // Only allow delete operations to the picture on the cover of the current resource
     $model = $this->model->find($id);
     $thumbnails = $model->thumbnails;
     if (is_null($thumbnails)) {
         return Redirect::back()->with('error', '没有找到对应的图片');
     } elseif ($thumbnails) {
         File::delete(public_path('uploads/job_category_thumbnails/' . $thumbnails));
         $model->thumbnails = NULL;
         $model->save();
         return Redirect::back()->with('success', '图片删除成功。');
     } else {
         return Redirect::back()->with('warning', '图片删除失败。');
     }
 }
Пример #14
0
 /**
  * Action: Delete resource images
  * @return Response
  */
 public function deleteUpload($id)
 {
     // Delete picture of current post
     $model = $this->model->find($id);
     $thumbnails = $model->thumbnails;
     if (is_null($thumbnails)) {
         return Redirect::back()->with('error', '没有找到对应的图片');
     } elseif ($thumbnails) {
         File::delete(public_path('uploads/category_thumbnails/' . $thumbnails));
         $model->thumbnails = NULL;
         $model->save();
         return Redirect::back()->with('success', '图片删除成功。');
     } else {
         return Redirect::back()->with('warning', '图片删除失败。');
     }
 }
Пример #15
0
 /**
  * Action: Delete resource images
  * @return Response
  */
 public function deleteUpload($id)
 {
     // Only allows you to share pictures on the cover of the current resource being deleted
     $filename = JobPictures::where('id', $id)->where('user_id', Auth::user()->id)->first();
     $oldImage = $filename->filename;
     $model = $this->model->find($filename->job_id);
     $oldThumbnails = $model->thumbnails;
     if (is_null($filename)) {
         return Redirect::back()->with('error', '没有找到对应的图片');
     } elseif ($filename->delete()) {
         destoryUploadImages($this->destinationPath, $oldImage);
         if ($oldImage == $oldThumbnails) {
             $model->thumbnails = NULL;
             $model->save();
             destoryUploadImages($this->thumbnailsPath, $oldThumbnails);
         }
         return Redirect::back()->with('success', '图片删除成功。');
     } else {
         return Redirect::back()->with('warning', '图片删除失败。');
     }
 }
Пример #16
0
 /**
  * Get Model by id.
  *
  * @param  int  $id
  * @return App\Models\Model
  */
 public function getById($id)
 {
     //dd($this->model);
     return $this->model->find($id);
 }