You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
monitor-doc/app/Mail/DocumentNotification.php

46 lines
1.1 KiB
PHP

<?php
namespace App\Mail;
use App\Models\Category;
use App\Models\Document;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class DocumentNotification extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct() {}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$docs = collect();
$categories = Category::all();
foreach($categories as $category) {
foreach($category->documents()->with(['variety'])->get() as $doc) {
if ($doc->is_close_due != 0) {
$docs->add($doc);
}
}
}
return $this->markdown('emails.document.notification', [
'documents' => $docs,
'dueDocuments' => Document::with(['variety'])->whereDate('due_date', '<=', now()->toDateString())->get()
]);
}
}