当前位置: 首页>>代码示例>>PHP>>正文


PHP Rating::findOrFail方法代码示例

本文整理汇总了PHP中Rating::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::findOrFail方法的具体用法?PHP Rating::findOrFail怎么用?PHP Rating::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rating的用法示例。


在下文中一共展示了Rating::findOrFail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 /**
  * Update the specified rating in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $rating = Rating::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Rating::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $rating->update($data);
     return Redirect::route('ratings.index');
 }
开发者ID:hopshoppub,项目名称:hopshop.dev,代码行数:16,代码来源:RatingsController.php

示例2: update

 /**
  * Update the specified rating in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $userId = Auth::user()->id;
     $ratingData = Rating::find($id);
     if ($userId === $ratingData["user_id"]) {
         $rating = Rating::findOrFail($id);
         $messages = array('new_stars.required' => 'We need to know how many stars you wish to give!', 'new_stars.max' => 'You must enter a value with a maximum value of 5.', 'new_comment.max' => 'You must enter a value with a maximum of 255 characters.', 'new_recommended.max' => 'You must enter a value with a maximum of 255 characters.');
         $validator = Validator::make($data = Input::all(), Rating::$new_rules, $messages);
         if ($validator->fails()) {
             return Redirect::back()->withErrors($validator)->withInput();
         } else {
             $rating->stars = Input::get('new_stars');
             $rating->comment = Input::get('new_comment');
             $rating->recommended = Input::get('new_recommended');
             $result = $rating->save();
         }
         if ($result) {
             Session::flash('successMessage', 'Your rating was successfully updated');
             return Redirect::route('ratings.index');
         } else {
             Session::flash('errorMessage', 'Please properly input all the required fields');
             Log::warning('Rating failed to save: ', Input::all());
             return Redirect::back()->withInput();
         }
     } else {
         return "Access Denied: this is not your rating.";
     }
 }
开发者ID:Park-It,项目名称:parkit.dev,代码行数:34,代码来源:RatingsController.php


注:本文中的Rating::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。