| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Models; |
| 4 |
|
| 5 |
use FluentForm\App\Helpers\Helper; |
| 6 |
|
| 7 |
class Subscription extends Model |
| 8 |
{ |
| 9 |
/** |
| 10 |
* The table associated with the model. |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
protected $table = 'fluentform_subscriptions'; |
| 15 |
|
| 16 |
/** |
| 17 |
* A subscription belongs to a form. |
| 18 |
* |
| 19 |
* @return \FluentForm\Framework\Database\Orm\Relations\BelongsTo |
| 20 |
*/ |
| 21 |
public function form() |
| 22 |
{ |
| 23 |
return $this->belongsTo(Form::class, 'form_id', 'id'); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* A subscription belongs to a submission. |
| 28 |
* |
| 29 |
* @return \FluentForm\Framework\Database\Orm\Relations\BelongsTo |
| 30 |
*/ |
| 31 |
public function submission() |
| 32 |
{ |
| 33 |
return $this->belongsTo(Submission::class, 'submission_id', 'id'); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* A subscription has many transactions. |
| 38 |
* |
| 39 |
* @return \FluentForm\Framework\Database\Orm\Relations\HasMany |
| 40 |
*/ |
| 41 |
public function transactions() |
| 42 |
{ |
| 43 |
return $this->hasMany(Transaction::class, 'subscription_id', 'id'); |
| 44 |
} |
| 45 |
|
| 46 |
public function getOriginalPlanAttribute($value) |
| 47 |
{ |
| 48 |
return Helper::safeUnserialize($value); |
| 49 |
} |
| 50 |
|
| 51 |
public function getVendorResponseAttribute($value) |
| 52 |
{ |
| 53 |
return Helper::safeUnserialize($value); |
| 54 |
} |
| 55 |
|
| 56 |
public function scopeBySubmission($query, $submissionId) |
| 57 |
{ |
| 58 |
return $query->where('submission_id', $submissionId); |
| 59 |
} |
| 60 |
|
| 61 |
public function scopeByVendorSubscriptionId($query, $vendorId) |
| 62 |
{ |
| 63 |
return $query->where('vendor_subscription_id', $vendorId); |
| 64 |
} |
| 65 |
|
| 66 |
public function scopeActive($query) |
| 67 |
{ |
| 68 |
return $query->where('status', 'active'); |
| 69 |
} |
| 70 |
} |
| 71 |
|