本文整理汇总了PHP中Poll::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::findOrFail方法的具体用法?PHP Poll::findOrFail怎么用?PHP Poll::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::findOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doPoll
public function doPoll()
{
if (!($pollId = \Input::get('poll_id', FALSE))) {
return FALSE;
}
$rules = array('poll_id' => 'required', 'answer' => 'required');
$validator = \Validator::make(\Input::all(), $rules);
if (!$validator->fails()) {
$poll = Poll::findOrFail($pollId);
for ($i = 1; $i <= 3; $i++) {
if (\Input::get('answer') == $poll->{'answer' . $i}) {
$poll->{'answer' . $i . '_count'}++;
$poll->save();
break;
}
}
if (\Request::ajax()) {
die(1);
}
}
return \Redirect::to(\Input::get('return'));
}
示例2: getDelete
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function getDelete($id)
{
if (Session::get('user_level') < Config::get('cms.deletePolls')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
try {
$poll = Poll::findOrFail($id);
$poll->delete();
return Redirect::to(_l(URL::action('PollController@getIndex')))->with('message', Lang::get('admin.PollDeleted'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('PollController@getIndex')))->with('message', Lang::get('admin.noSuchPoll'))->with('notif', 'danger');
}
}
示例3: getPollResults
public function getPollResults($id)
{
try {
$this->googleAnalytics('/polls/poll-results/' . $id);
$poll = Poll::findOrFail($id);
$poll_options = PollOption::where('poll_id', '=', $id)->orderBy('vote_count', 'asc')->get();
foreach ($poll_options as $key => $option) {
$poll_options[$key]->title = __($option->title);
}
$total_votes = PollOPtion::where('poll_id', '=', $id)->sum('vote_count');
$response = array("status" => 'success', "poll" => $poll, "poll_options" => $poll_options, "total_votes" => $total_votes, "totalvotes" => "Укупно " . $total_votes . " гласова");
return Response::json($response);
} catch (Exception $e) {
return Response::json(array("status" => "success", "text" => __("Десила се грешка")));
}
}