本文整理汇总了PHP中Section::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Section::findOrFail方法的具体用法?PHP Section::findOrFail怎么用?PHP Section::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Section
的用法示例。
在下文中一共展示了Section::findOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyVote
public function applyVote($user, $type, $type_id, $updown)
{
//deal with item table
$item = "";
switch ($type) {
case Constant::POST_TYPE:
$item = Post::findOrFail($type_id);
break;
case Constant::COMMENT_TYPE:
$item = Comment::findOrFail($type_id);
Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $item->post_id);
break;
case Constant::SECTION_TYPE:
$item = Section::findOrFail($type_id);
break;
default:
throw new UnexpectedValueException("type: {$type} not enumerated");
}
//increment our total vote counter
$user->increment('votes');
//decrement one point for voting
$user->decrement('points');
//double decrement for self upvote
if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
if ($item->user_id == Auth::user()->id && $updown == Constant::VOTE_UP) {
$user->decrement('points');
}
}
//upvote/downvote the item itself
if ($updown == Constant::VOTE_UP) {
$item->increment('upvotes');
} else {
if ($updown == Constant::VOTE_DOWN) {
$item->increment('downvotes');
}
}
//upvote/downvote user who posted (ignore for sections)
if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
$rec_user = User::findOrFail($item->user_id);
if ($updown == Constant::VOTE_UP) {
$rec_user->increment('points');
} else {
if ($updown == Constant::VOTE_DOWN) {
$rec_user->decrement('points');
}
}
}
//deal with votes table
$vote = new Vote(array('type' => $type, 'user_id' => Auth::user()->id, 'item_id' => $type_id, 'updown' => $updown));
$vote->save();
}
示例2: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$section = Section::findOrFail($id);
$section->delete();
return Redirect::route('admin.sections.index');
}
示例3: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$section = $this->section->findOrFail($id);
return View::make('sections.show', compact('section'));
}