本文整理汇总了PHP中Vote::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Vote::firstOrNew方法的具体用法?PHP Vote::firstOrNew怎么用?PHP Vote::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vote
的用法示例。
在下文中一共展示了Vote::firstOrNew方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: vote
public function vote($id)
{
$qa = Qa::findOrFail($id);
// +1 or -1
$voteValue = Input::get('vote');
$vote = Vote::firstOrNew(['user_id' => Auth::id(), 'voteable_id' => $id, 'voteable_type' => 'Qa']);
$vote->vote = $voteValue;
$vote->save();
return Redirect::back();
}
示例2: castVote
protected function castVote($id, $value)
{
$vote = Vote::firstOrNew(['user_id' => Auth::id(), 'voteable_id' => $id, 'voteable_type' => 'Note']);
$vote->vote = $value;
$vote->save();
return Redirect::back();
}
示例3: starSkin
function starSkin($id)
{
$skin = Skin::find($id);
$star = Vote::firstOrNew(array("user_id" => Auth::user()->id, "skin_id" => $id));
$userstar = Vote::where("user_id", Auth::user()->id)->where("skin_id", $id)->first();
if (isset($userstar)) {
$userstar->delete();
$skin->votes -= 1;
} else {
$skin->votes += 1;
$star->save();
}
$skin->save();
return Response::json("success");
}