本文整理汇总了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');
}
示例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.";
}
}