|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\EmailCampaigns\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Spatie\EmailCampaigns\Support\Config; |
|
7
|
|
|
use Spatie\EmailCampaigns\Actions\SubscribeAction; |
|
8
|
|
|
use Spatie\EmailCampaigns\Models\Concerns\HasUuid; |
|
9
|
|
|
use Spatie\EmailCampaigns\Enums\SubscriptionStatus; |
|
10
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough; |
|
11
|
|
|
|
|
12
|
|
|
class Subscriber extends Model |
|
13
|
|
|
{ |
|
14
|
|
|
use HasUuid; |
|
15
|
|
|
|
|
16
|
|
|
public $table = 'email_list_subscribers'; |
|
17
|
|
|
|
|
18
|
|
|
protected $guarded = []; |
|
19
|
|
|
|
|
20
|
|
|
public static function findForEmail(string $email): ?Subscriber |
|
21
|
|
|
{ |
|
22
|
|
|
return static::where('email', $email)->first(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function emailLists(): HasManyThrough |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->hasManyThrough(EmailList::class, Subscription::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function subscribeTo(EmailList $emailList, bool $respectDoubleOptIn = true): Subscription |
|
31
|
|
|
{ |
|
32
|
|
|
$action = Config::getActionClass('subscribe_action', SubscribeAction::class); |
|
33
|
|
|
|
|
34
|
|
|
return $action->execute($this, $emailList, $respectDoubleOptIn); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function subscribeNowTo(EmailList $emailList) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->subscribeTo($emailList, false); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function isSubscribedTo(EmailList $emailList): bool |
|
43
|
|
|
{ |
|
44
|
|
|
return Subscription::query() |
|
|
|
|
|
|
45
|
|
|
->where('email_list_subscriber_id', $this->id) |
|
46
|
|
|
->where('email_list_id', $emailList->id) |
|
47
|
|
|
->where('status', SubscriptionStatus::SUBSCRIBED) |
|
48
|
|
|
->exists(); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.