Completed
Push — master ( de720f...c28053 )
by Freek
01:25 queued 11s
created

CampaignSend::findByTransportMessageId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\EmailCampaigns\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\EmailCampaigns\Models\Concerns\HasUuid;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
9
class CampaignSend extends Model
10
{
11
    use HasUuid;
12
13
    public $table = 'email_campaign_sends';
14
15
    public $guarded = [];
16
17
    public $dates = ['sent_at'];
18
19
    public static function findByTransportMessageId(string $transportMessageId): ?Model
20
    {
21
        return static::where('transport_message_id', $transportMessageId)->first();
22
    }
23
24
    public function subscription(): BelongsTo
25
    {
26
        return $this->belongsTo(Subscription::class, 'email_list_subscription_id');
27
    }
28
29
    public function campaign(): BelongsTo
30
    {
31
        return $this->belongsTo(Campaign::class, 'email_campaign_id');
32
    }
33
34
    public function markAsSent()
35
    {
36
        $this->sent_at = now();
37
38
        $this->save();
39
40
        return $this;
41
    }
42
43
    public function wasAlreadySent(): bool
44
    {
45
        return ! is_null($this->sent_at);
46
    }
47
}
48