예제 #1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     if (Auth::check() && null !== Request::input('text')) {
         $text = Request::input('text');
         $ad_id = Request::input('ad_id');
         $comment = new Comment();
         $comment->author_id = Auth::user()->id;
         $comment->ad_id = $ad_id;
         $comment->text = $text;
         if (null !== Request::input('answer_to')) {
             $comment->answer_to = Request::input('answer_to');
         }
         if (null !== Request::input('is_private')) {
             $comment->is_private = true;
         }
         $comment->save();
         // Mail
         $ad = $comment->ad;
         $data = ['username' => $comment->answer_to == null ? $ad->author->name : $comment->answerTo->author->name, 'ad_title' => $ad->title, 'ad_id' => $ad->id, 'comment_text' => $comment->text];
         if ($comment->answer_to == null) {
             if ($ad->author->email != null) {
                 Mail::send('emails.new_question', $data, function ($m) use($ad) {
                     $m->from('*****@*****.**', 'Хоам');
                     $m->to($ad->author->email, $ad->author->name)->subject('Уведомление о новом вопросе');
                 });
             }
         } else {
             $question_author = $comment->answerTo->author;
             if ($question_author->email != null) {
                 Mail::send('emails.new_answer', $data, function ($m) use($ad, $question_author) {
                     $m->from('*****@*****.**', 'Хоам');
                     $m->to($question_author->email, $question_author->name)->subject('Уведомление о новом ответе');
                 });
             }
         }
         return view('sub.comments', ['ad' => Ad::whereId($ad_id)->firstOrFail()]);
     } else {
         return 'error';
     }
 }
예제 #2
0
 public function refresh($id)
 {
     if (Auth::check()) {
         $ad = Ad::whereId($id)->first();
         $leftToRefresh = 3 - floor((time() - strtotime($ad->created_at)) / 86400);
         if ($ad->author_id == Auth::user()->id && $leftToRefresh <= 0) {
             $ad->created_at = date('Y-m-d G:i:s');
             $ad->save();
             return 1;
         }
     }
 }