Skip to content

Commit 54b15fd

Browse files
committed
feat: add subscriptions trait
1 parent 23cdc71 commit 54b15fd

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Auth/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class User
1717
{
1818
use UsesRoles;
19+
use UsesSubscriptions;
1920

2021
/**
2122
* Internal instance of Leaf database

src/Auth/UsesSubscriptions.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Leaf\Auth;
4+
5+
/**
6+
* Functionality for user subscriptions
7+
* ----
8+
* Addition to user class
9+
*
10+
* @version 0.1.0
11+
* @since 4.1.0
12+
*/
13+
trait UsesSubscriptions
14+
{
15+
/**
16+
* User Subscription
17+
* @var array|null
18+
*/
19+
protected $subscription = null;
20+
21+
/**
22+
* Get current subscription
23+
*
24+
* @param string|array $subscription The subscription to assign
25+
* @return array|null
26+
*/
27+
public function subscription()
28+
{
29+
if (!$this->subscription) {
30+
$this->subscription = db()
31+
->select('subscriptions')
32+
->where('user_id', $this->id())
33+
->first();
34+
35+
$this->subscription['tier'] = billing()->tier($this->subscription['plan_id']);
36+
}
37+
38+
return $this->subscription;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)