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

CampaignSend::unsubscribeUrl()   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 0
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