Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| UserAddOns | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
6.10 | |
0.00% |
0 / 1 |
| getSourceAttribute | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| toArray | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addOn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| newFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models; |
| 4 | |
| 5 | use Database\Factories\Http\Models\UserAddOnsFactory; |
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 7 | use MongoDB\Laravel\Eloquent\SoftDeletes; |
| 8 | |
| 9 | class UserAddOns extends Moloquent |
| 10 | { |
| 11 | use HasFactory, SoftDeletes; |
| 12 | |
| 13 | public const SOURCE_INDIVIDUAL = 'individual'; |
| 14 | |
| 15 | public const SOURCE_COMPANY = 'company'; |
| 16 | |
| 17 | protected $fillable = [ |
| 18 | 'user_id', |
| 19 | 'add_on_id', |
| 20 | 'stripe_id', |
| 21 | 'stripe_price_id', |
| 22 | 'quantity', |
| 23 | 'status', |
| 24 | 'starts_at', |
| 25 | 'ends_at', |
| 26 | 'product', |
| 27 | 'source', |
| 28 | 'created_at', |
| 29 | 'updated_at', |
| 30 | ]; |
| 31 | |
| 32 | protected $attributes = [ |
| 33 | 'source' => self::SOURCE_INDIVIDUAL, |
| 34 | ]; |
| 35 | |
| 36 | /** |
| 37 | * Returns the addon source, defaulting to "individual" for legacy rows |
| 38 | * that were created before the field existed. |
| 39 | */ |
| 40 | public function getSourceAttribute($value): string |
| 41 | { |
| 42 | return $value ?: self::SOURCE_INDIVIDUAL; |
| 43 | } |
| 44 | |
| 45 | public function toArray(): array |
| 46 | { |
| 47 | $array = parent::toArray(); |
| 48 | $array['source'] = $this->source; |
| 49 | |
| 50 | return $array; |
| 51 | } |
| 52 | |
| 53 | public function user() |
| 54 | { |
| 55 | return $this->belongsTo(User::class, 'user_id'); |
| 56 | } |
| 57 | |
| 58 | public function addOn() |
| 59 | { |
| 60 | return $this->belongsTo(AddOns::class, 'add_on_id'); |
| 61 | } |
| 62 | |
| 63 | protected static function newFactory() |
| 64 | { |
| 65 | return UserAddOnsFactory::new(); |
| 66 | } |
| 67 | } |