本文整理汇总了PHP中Comment::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::findOrFail方法的具体用法?PHP Comment::findOrFail怎么用?PHP Comment::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Comment
的用法示例。
在下文中一共展示了Comment::findOrFail方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbsDown
public function getThumbsDown($id)
{
try {
$this->googleAnalytics('/comments/thumbs-down/' . $id);
$valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 2)->where('object_id', '=', $id)->first();
if ($valid_ip != null) {
throw new Exception("Error valid IP", 1);
}
$comment = Comment::findOrFail($id);
$comment->thumbs_down++;
$comment->save();
$thumb = new Thumb();
$thumb->ip = Puskice::getIP();
$thumb->object_id = $comment->id;
$thumb->object_type = 2;
$thumb->save();
$thumbs = array();
if (Cookie::get('ps_thumbs')) {
$cookie = Cookie::get('ps_thumbs');
$thumbs = unserialize($cookie);
if (isset($thumbs['comments'][$comment->id])) {
return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили овај коментар")));
}
}
$thumbs['comments'][$comment->id] = 'down';
Cookie::queue('ps_thumbs', serialize($thumbs), 2628000);
return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $comment->thumbs_up, 'thumbsDown' => $comment->thumbs_down));
} catch (Exception $e) {
return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили овај коментар")));
}
}
示例2: destroy
public function destroy($id)
{
$comment = Comment::findOrFail($id);
$this->authorOrAdminPermissioinRequire($comment->user_id);
Comment::destroy($id);
Flash::success(lang('Operation succeeded.'));
return Redirect::route('posts.show', $comment->post_id);
}
示例3: update
/**
* Update the specified comment in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$comment = Comment::findOrFail($id);
$validator = Validator::make($data = Input::all(), Comment::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$comment->update($data);
return Redirect::route('comments.index');
}
示例4: 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();
}
示例5: delete_comment
public function delete_comment($article_id, $comment_id)
{
$commentReference = Comment::findOrFail($comment_id);
$commentsAuthor = $commentReference->user()->first();
$commentsAuthor = $commentsAuthor;
if (Auth::check() && Auth::user()->username == $commentsAuthor->username || Auth::user()->isAdmin()) {
Comment::destroy($comment_id);
return Redirect::to(URL::previous());
} else {
return Redirect::route('login');
}
}
示例6: getDelete
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function getDelete($id)
{
if (Session::get('user_level') < Config::get('cms.deleteComments')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
try {
$comment = Comment::findOrFail($id);
$comment->delete();
return Redirect::to(_l(URL::action('CommentController@getIndex')))->with('message', Lang::get('admin.commentDeleted'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('CommentController@getIndex')))->with('message', Lang::get('admin.noSuchComment'))->with('notif', 'danger');
}
}
示例7: getPaste
/**
* Displays the default view page
*
* @access public
* @param string $urlkey
* @param string $hash
* @param string $action
* @param string $extra
* @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect|null
*/
public function getPaste($urlkey, $hash = '', $action = '', $extra = '')
{
$site = Site::config('general');
$paste = Paste::where('urlkey', $urlkey)->first();
// Paste was not found
if (is_null($paste)) {
App::abort(404);
// Not found
}
// Check if the logged in user is the owner of the paste
$owner = Auth::access($paste->author_id);
// We do not make password prompt mandatory for owners
if (!$owner) {
// Require hash to be passed for private pastes
if ($paste->private and $paste->hash != $hash) {
App::abort(401);
// Unauthorized
}
// Check if paste is password protected and user hasn't entered
// the password yet
if ($paste->password and !Session::has('paste.password' . $paste->id)) {
return View::make('site/password', array());
}
}
// Increment the hit counter
if (!Session::has('paste.viewed' . $paste->id)) {
$paste->hits++;
$paste->save();
Session::put('paste.viewed' . $paste->id, TRUE);
}
// Let's do some action!
switch ($action) {
case 'delete':
if (empty($extra)) {
// Delete the paste if the user has access
if ($site->allowPasteDel and $owner) {
Revision::where('urlkey', $paste->urlkey)->delete();
$paste->comments()->delete();
$attachment = storage_path() . "/uploads/{$paste->urlkey}";
if ($paste->attachment and File::exists($attachment)) {
File::delete($attachment);
}
$paste->delete();
Session::flash('messages.success', Lang::get('global.paste_deleted'));
return Redirect::to('/');
} else {
App::abort(401);
// Unauthorized
}
} else {
if (is_numeric($extra)) {
$comment = Comment::findOrFail($extra);
// Delete the comment if the user has access
if ($owner or Auth::user()->username == $comment->author) {
$comment->delete();
} else {
App::abort(401);
// Unauthorized
}
}
}
return Redirect::to(URL::previous());
case 'raw':
$response = Response::make($paste->data);
$response->header('Content-Type', 'text/plain');
return $response;
case 'toggle':
if ($owner) {
Revision::where('urlkey', $paste->urlkey)->delete();
$paste->private = $paste->private ? 0 : 1;
$paste->password = '';
$paste->save();
}
return Redirect::to(URL::previous());
case 'flag':
if ($site->flagPaste == 'all' or $site->flagPaste == 'user' and Auth::roles()->user) {
$paste->flagged = 1;
$paste->save();
Cache::forget('global.flags');
Session::flash('messages.success', Lang::get('global.paste_flagged'));
} else {
App::abort(401);
// Unauthorized
}
return Redirect::to(URL::previous());
case 'unflag':
if (Auth::roles()->admin) {
$paste->flagged = 0;
$paste->save();
Cache::forget('global.flags');
//.........这里部分代码省略.........
示例8: vote
public function vote($id)
{
$Comment = Comment::findOrFail($id);
// +1 or -1
$voteValue = Input::get('vote');
$vote = Vote::firstOrNew(['user_id' => Auth::id(), 'voteable_id' => $id, 'voteable_type' => 'Comment']);
$vote->vote = $voteValue;
$vote->save();
return Redirect::back();
}