*/ use HasFactory, HasUuid; protected $fillable = ['user_id', 'name', 'email', 'locale', 'stripe_customer_id', 'status']; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function orders(): HasMany { return $this->hasMany(Order::class); } public function instances(): HasMany { return $this->hasMany(Instance::class); } /** Find or create the portal login account for this customer and link it. */ public function ensureUser(): User { if ($this->user) { return $this->user; } $user = User::query()->firstOrCreate( ['email' => $this->email], ['name' => $this->name, 'password' => Hash::make(Str::random(40)), 'is_admin' => false], ); $this->update(['user_id' => $user->id]); return $user->refresh(); } }