Skip to content

Commit 13773bf

Browse files
committedNov 29, 2018
完善了提醒邮件
1 parent ca35455 commit 13773bf

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed
 

‎app/Http/Controllers/CommentController.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ public function store(Request $request)
2626
if ($request->parent_id) {
2727
$comment->parent_id = $request->parent_id;
2828
$comment->target_id = $request->target_id;
29-
Mail::to(Comment::findOrFail($request->target_id)->email)->send(new CommentRemind);
3029
}else {
3130
$comment->parent_id = 0;
3231
$comment->target_id = 0;
33-
Mail::to(User::findOrFail(1))->send(new CommentRemind);
3432
}
3533
$comment->article_id = $request->article_id;
3634
$comment->content = $request->content;
@@ -40,6 +38,22 @@ public function store(Request $request)
4038
$comment->ip = $request->ip();
4139
// $comment->city = $city['region'].' '.$city['city'];
4240
$comment->save();
41+
42+
//发送邮件
43+
if ($request->parent_id) {
44+
$commentTarget = Comment::findOrFail($request->target_id);
45+
$url = url("/articles/{$comment->article->id}#comment{$comment->id}");
46+
try {
47+
Mail::to($commentTarget->email)
48+
->send(new CommentRemind($commentTarget->content, $comment, $url));
49+
}catch (\Exception $e) {}
50+
}else {
51+
$url = url("/articles/{$comment->article->id}#comment{$comment->id}");
52+
try {
53+
Mail::to(User::findOrFail(1))
54+
->send(new CommentRemind($comment->article->title, $comment, $url));
55+
}catch (\Exception $e) {}
56+
}
4357
return back()->with('message', '留言成功!');
4458
}
4559
}

‎app/Mail/CommentRemind.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ class CommentRemind extends Mailable
1616
*
1717
* @return void
1818
*/
19-
public function __construct()
19+
public function __construct($title, $comment, $url)
2020
{
21-
//
21+
$this->subject('Re:' . $title);
22+
$this->title = $title;
23+
$this->comment = $comment;
24+
$this->url = $url;
2225
}
2326

2427
/**
@@ -28,6 +31,11 @@ public function __construct()
2831
*/
2932
public function build()
3033
{
31-
return $this->view('emails.comments.remind');
34+
return $this->view('emails.comments.remind')
35+
->with([
36+
'title' => $this->title,
37+
'comment' => $this->comment,
38+
'url' => $this->url,
39+
]);;
3240
}
3341
}

‎resources/views/emails/comments/remind.blade.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<title>TEST TITLE</title>
99
</head>
1010
<body>
11-
<h1>TEST</h1>
11+
<h4>您发布的内容 “{{ $title }}” 收到了回复:</h4>
12+
<p> {{ $comment->name }}{{ $comment->content }} </p>
13+
<p><a href="{{ $url }}">点此查看</a></p>
1214
</body>
1315
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.