File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
6+ use Illuminate \Database \Eloquent \Model ;
7+ use Illuminate \Database \Eloquent \Relations \BelongsTo ;
8+ use Laravel \Cashier \SubscriptionItem ;
9+
10+ class License extends Model
11+ {
12+ use HasFactory;
13+
14+ protected $ guarded = [];
15+
16+ protected $ casts = [
17+ 'expires_at ' => 'datetime ' ,
18+ ];
19+
20+ /**
21+ * @return BelongsTo<User>
22+ */
23+ public function user (): BelongsTo
24+ {
25+ return $ this ->belongsTo (User::class);
26+ }
27+
28+ /**
29+ * @return BelongsTo<SubscriptionItem>
30+ */
31+ public function subscriptionItem (): BelongsTo
32+ {
33+ return $ this ->belongsTo (SubscriptionItem::class);
34+ }
35+ }
Original file line number Diff line number Diff line change 44
55// use Illuminate\Contracts\Auth\MustVerifyEmail;
66use Illuminate \Database \Eloquent \Factories \HasFactory ;
7+ use Illuminate \Database \Eloquent \Relations \HasMany ;
78use Illuminate \Foundation \Auth \User as Authenticatable ;
89use Illuminate \Notifications \Notifiable ;
910use Laravel \Cashier \Billable ;
@@ -24,4 +25,12 @@ class User extends Authenticatable
2425 'email_verified_at ' => 'datetime ' ,
2526 'password ' => 'hashed ' ,
2627 ];
28+
29+ /**
30+ * @return HasMany<License>
31+ */
32+ public function licenses (): HasMany
33+ {
34+ return $ this ->hasMany (License::class);
35+ }
2736}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Database \Factories ;
4+
5+ use App \Enums \Subscription ;
6+ use App \Models \License ;
7+ use App \Models \User ;
8+ use Illuminate \Database \Eloquent \Factories \Factory ;
9+ use Illuminate \Support \Facades \Date ;
10+ use Laravel \Cashier \SubscriptionItem ;
11+
12+ /**
13+ * @extends Factory<License>
14+ */
15+ class LicenseFactory extends Factory
16+ {
17+ public function definition (): array
18+ {
19+ return [
20+ 'user_id ' => User::factory (),
21+ 'subscription_item_id ' => SubscriptionItem::factory (),
22+ 'policy_name ' => fake ()->randomElement (Subscription::cases ())->value ,
23+ 'key ' => fake ()->uuid (),
24+ 'created_at ' => fake ()->dateTimeBetween ('-1 year ' , 'now ' ),
25+ 'updated_at ' => fn (array $ attrs ) => $ attrs ['created_at ' ],
26+ 'expires_at ' => fn (array $ attrs ) => Date::parse ($ attrs ['created_at ' ])->addYear (),
27+ ];
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments