Completed
Push — master ( abe693...b4d6e4 )
by Freek
01:15
created

CampaignSend   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A subscription() 0 4 1
A campaign() 0 4 1
A markAsSent() 0 8 1
A wasAlreadySent() 0 4 1
A unsubscribeUrl() 0 4 1
1
<?php
2
3
namespace Spatie\EmailCampaigns\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\EmailCampaigns\Http\Controllers\UnsubscribeController;
7
use Spatie\EmailCampaigns\Models\Concerns\HasUuid;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
10
class CampaignSend extends Model
11
{
12
    use HasUuid;
13
14
    public $table = 'email_campaign_sends';
15
16
    public $guarded = [];
17
18
    public $dates = ['sent_at'];
19
20
    public function subscription(): BelongsTo
21
    {
22
        return $this->belongsTo(Subscription::class, 'email_list_subscription_id');
23
    }
24
25
    public function campaign(): BelongsTo
26
    {
27
        return $this->belongsTo(Campaign::class, 'email_campaign_id');
28
    }
29
30
    public function markAsSent()
31
    {
32
        $this->sent_at = now();
33
34
        $this->save();
35
36
        return $this;
37
    }
38
39
    public function wasAlreadySent(): bool
40
    {
41
        return ! is_null($this->sent_at);
42
    }
43
44
    public function unsubscribeUrl(): string
45
    {
46
        return url(action(UnsubscribeController::class, $this->subscription->uuid));
47
    }
48
}
49