1 | <?php |
||
2 | |||
3 | namespace App\Mail; |
||
4 | |||
5 | use App\Models\User; |
||
6 | use Illuminate\Bus\Queueable; |
||
7 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
8 | use Illuminate\Mail\Mailable; |
||
9 | use Illuminate\Queue\SerializesModels; |
||
10 | |||
11 | class AuthorDigestMail extends Mailable implements ShouldQueue |
||
12 | { |
||
13 | use Queueable, SerializesModels; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
14 | |||
15 | public $user; |
||
16 | |||
17 | /** |
||
18 | * Create a new message instance. |
||
19 | * |
||
20 | * @return void |
||
21 | */ |
||
22 | public function __construct(User $user) |
||
23 | { |
||
24 | $this->user = $user; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Build the message. |
||
29 | * |
||
30 | * @return $this |
||
31 | * |
||
32 | * @throws \Exception |
||
33 | */ |
||
34 | public function build() |
||
35 | { |
||
36 | $quizzes = $this->user->quizzes() |
||
37 | ->where('author_digest', 1) |
||
38 | ->with('attempts', function ($query) { |
||
39 | $query->whereDate('submitted_at', today()->subDay()) |
||
40 | ->groupByRaw('quiz_id, user_id') |
||
41 | ->with('user') |
||
42 | ->selectRaw('`quiz_id`, `user_id`, COUNT(`user_id`) as attempts_count, MAX(`marks`) as `max_marks`, MIN(`marks`) as min_marks, AVG(`marks`) as avg_marks'); |
||
43 | }) |
||
44 | ->get(); |
||
45 | |||
46 | if (empty($quizzes)) { |
||
47 | throw new \Exception(); |
||
48 | } |
||
49 | |||
50 | return $this->subject('Daily Digest from '.config('app.name')) |
||
51 | ->markdown('emails.author_digest', [ |
||
52 | 'quizzes' => $quizzes, |
||
53 | ]); |
||
54 | } |
||
55 | } |
||
56 |