示例#1
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $topic = Topic::findOrFail($this->input('topic_id'));
     if ($topic->is_blocked) {
         return false;
     } else {
         return true;
     }
 }
示例#2
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check() && Auth::user()->can('manage_topics')) {
         $this->topic = Topic::findOrFail($this->route('id'));
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $this->topic = Topic::findOrFail($this->route('id'));
     //patikrinam ar useris turi teise redaguoti tema.
     if (Auth::check() && (Auth::user()->id == $this->topic->user_id && !$this->topic->is_blocked) || Auth::user()->can('manage_topics')) {
         return true;
     } else {
         return false;
     }
 }
示例#4
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $user = Auth::user();
     $topic = Topic::findOrFail($this->route('id'));
     $this->topic = $topic;
     if ($user && ($topic->user_id == $user->id && !$this->topic->is_blocked || $user->can('manage_topics'))) {
         return true;
     } else {
         return false;
     }
 }
示例#5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $topic = Topic::findOrFail($this->argument('topic_id'));
     $users = User::where('email_news', 1)->chunk(200, function ($users) use($topic) {
         $data = ['title' => $topic->title, 'body' => $topic->body];
         foreach ($users as $user) {
             Mail::queue('emails.news', $data, function ($message) use($user, $topic) {
                 $message->to($user->email)->subject('Maze Naujienos: ' . utf8_urldecode($topic->title));
             });
         }
     });
 }
示例#6
0
 public function markAnswer(AnswerReply $request, $id)
 {
     //Pažymim atsakymą.
     $reply = Reply::findOrFail($id);
     $reply->is_answer = 1;
     $reply->user->increment('karma_count', 5);
     $reply->save();
     //Užrakinam temą.
     $topic = Topic::findOrFail($reply->topic_id);
     $topic->is_blocked = 1;
     $topic->is_answered = 1;
     $topic->save();
     flash()->success('Pranešimas pažymėtas kaip atsakymas!');
     return redirect()->route('topic.show', [$topic->slug]);
 }
示例#7
0
 public function vote(VoteRequest $request, $vote, $type, $id)
 {
     $user = Auth::user();
     if ($type == 'tema') {
         $type = 'Topic';
         $_votable = Topic::findOrFail($id);
     } else {
         $type = 'Reply';
         $_votable = Reply::findOrFail($id);
     }
     $_vote = Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->first();
     //Ištrinam visus balsus, jei netyčia susibugintų.
     if ($_vote) {
         Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->delete();
         if ($_vote->is != $vote) {
             $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
             //cancel old vote and give new vote
             if ($vote == 'upvote') {
                 event(new UpVoted($_votable, $created_vote, $_votable->user, true));
             } else {
                 event(new DownVoted($_votable, $created_vote, $_votable->user, true));
             }
         } else {
             //cancel current vote
             if ($vote == 'upvote') {
                 event(new DownVoted($_votable, $_vote, $_votable->user, false));
             } else {
                 event(new UpVoted($_votable, $_vote, $_votable->user, false));
             }
         }
     } else {
         $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
         //just vote
         if ($vote == 'upvote') {
             event(new UpVoted($_votable, $created_vote, $_votable->user, false));
         } else {
             event(new DownVoted($_votable, $created_vote, $_votable->user, false));
         }
     }
     return response('success', 200);
 }