Fix 500 when exiting hosting panel for existing accounts.
Deploy Ladill Hosting / deploy (push) Successful in 20s

The account overview queried a local mailboxes table that the extracted hosting app does not have; guard those lookups and skip email-addon upsells when mailboxes are managed on Ladill Email.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-06 17:02:44 +00:00
co-authored by Cursor
parent 206a022e27
commit 1135915797
5 changed files with 62 additions and 21 deletions
+29 -3
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use Carbon\CarbonInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Model;
@@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Schema;
class HostingAccount extends Model
{
@@ -159,6 +161,28 @@ class HostingAccount extends Model
return $this->hasMany(Mailbox::class, 'hosting_account_id');
}
/** The extracted hosting app does not store mailboxes locally — they live on Ladill Email. */
public static function tracksLocalMailboxes(): bool
{
static $hasTable = null;
return $hasTable ??= Schema::hasTable('mailboxes');
}
/** @return Collection<int, Mailbox> */
public function loadedMailboxes(): Collection
{
if (! static::tracksLocalMailboxes()) {
return new Collection;
}
if (! $this->relationLoaded('mailboxes')) {
$this->load('mailboxes');
}
return $this->mailboxes;
}
public function billingInvoices(): HasMany
{
return $this->hasMany(HostingBillingInvoice::class, 'hosting_account_id');
@@ -268,9 +292,11 @@ class HostingAccount extends Model
public function paidMailboxCount(): int
{
return $this->relationLoaded('mailboxes')
? $this->mailboxes->where('is_paid', true)->count()
: $this->mailboxes()->where('is_paid', true)->count();
if (! static::tracksLocalMailboxes()) {
return 0;
}
return $this->loadedMailboxes()->where('is_paid', true)->count();
}
public function renew(?int $durationMonths = null, array $metadata = []): void