|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model\Product; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use DateTimeZone; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
8
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
|
9
|
|
|
|
|
10
|
|
|
class Subscription extends Model |
|
11
|
|
|
{ |
|
12
|
|
|
use LogsActivity; |
|
13
|
|
|
protected $table = 'subscriptions'; |
|
14
|
|
|
protected $fillable = ['name', 'description', 'days', 'ends_at', |
|
15
|
|
|
'user_id', 'plan_id', 'order_id', 'deny_after_subscription', 'version', 'product_id', ]; |
|
16
|
|
|
protected $dates = ['ends_at']; |
|
17
|
|
|
protected static $logName = 'Subscription'; |
|
18
|
|
|
protected static $logAttributes = ['ends_at', 'user_id', 'plan_id', 'order_id', 'version', 'product_id']; |
|
19
|
|
|
protected static $logOnlyDirty = true; |
|
20
|
|
|
|
|
21
|
|
|
public function getDescriptionForEvent(string $eventName): string |
|
22
|
|
|
{ |
|
23
|
|
|
if ($eventName == 'created') { |
|
24
|
|
|
// dd($this->user()->get()->toArray(), 'cxzc'); |
|
25
|
|
|
return 'Subscription for User_Id <strong> '.$this->user_id.' </strong> was created'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if ($eventName == 'updated') { |
|
29
|
|
|
return 'Subscription for User <strong> '.$this->user_id.'</strong> was updated'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ($eventName == 'deleted') { |
|
33
|
|
|
return 'Subscription for User <strong> '.$this->user_id.' </strong> was deleted'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return ''; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function plan() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->belongsTo('App\Model\Payment\Plan'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function user() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->belongsTo('App\User'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function order() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->belongsTo('App\Model\Order\Order'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
// public function getEndsAtAttribute($value) |
|
56
|
|
|
// { |
|
57
|
|
|
// $date1 = new DateTime($value); |
|
58
|
|
|
// $tz = \Auth::user()->timezone()->first()->name; |
|
59
|
|
|
// $date1->setTimezone(new DateTimeZone($tz)); |
|
60
|
|
|
// $date = $date1->format('M j, Y, g:i a '); |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
// return $date; |
|
64
|
|
|
// } |
|
65
|
|
|
|
|
66
|
|
|
// public function delete() { |
|
67
|
|
|
// |
|
68
|
|
|
// |
|
69
|
|
|
// $this->Plan()->delete(); |
|
70
|
|
|
// |
|
71
|
|
|
// |
|
72
|
|
|
// return parent::delete(); |
|
73
|
|
|
// } |
|
74
|
|
|
} |
|
75
|
|
|
|