softdeletes für packages eingerichtet
This commit is contained in:
@@ -11,7 +11,11 @@ use Filament\Actions;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
@@ -29,8 +33,12 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules\Unique;
|
||||
use UnitEnum;
|
||||
|
||||
class PackageResource extends Resource
|
||||
@@ -86,7 +94,10 @@ class PackageResource extends Resource
|
||||
->label('Slug')
|
||||
->required()
|
||||
->maxLength(191)
|
||||
->unique(ignoreRecord: true),
|
||||
->unique(
|
||||
ignoreRecord: true,
|
||||
modifyRuleUsing: fn (Unique $rule) => $rule->withoutTrashed()
|
||||
),
|
||||
Select::make('type')
|
||||
->label('Paket-Typ')
|
||||
->options([
|
||||
@@ -272,6 +283,7 @@ class PackageResource extends Resource
|
||||
'endcustomer' => 'Endkunde',
|
||||
'reseller' => 'Reseller',
|
||||
]),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Actions\Action::make('syncPaddle')
|
||||
@@ -305,15 +317,31 @@ class PackageResource extends Resource
|
||||
}),
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
DeleteAction::make()
|
||||
->visible(fn (Package $record) => ! $record->trashed()),
|
||||
RestoreAction::make()
|
||||
->visible(fn (Package $record) => $record->trashed()),
|
||||
ForceDeleteAction::make()
|
||||
->visible(fn (Package $record) => $record->trashed())
|
||||
->requiresConfirmation(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
ForceDeleteBulkAction::make()->requiresConfirmation(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -36,7 +36,7 @@ class AbandonedCheckout extends Model
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
return $this->belongsTo(Package::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ class CheckoutSession extends Model
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
return $this->belongsTo(Package::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
|
||||
@@ -39,7 +39,7 @@ class EventPackage extends Model
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
return $this->belongsTo(Package::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
|
||||
@@ -6,10 +6,12 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Package extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
||||
@@ -46,7 +46,7 @@ class PackagePurchase extends Model
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
return $this->belongsTo(Package::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function isEndcustomerEvent(): bool
|
||||
|
||||
@@ -222,7 +222,7 @@ class Tenant extends Model
|
||||
public function getActiveResellerPackage(): ?TenantPackage
|
||||
{
|
||||
return $this->activeResellerPackage()
|
||||
->whereHas('package', fn ($query) => $query->where('type', 'reseller'))
|
||||
->whereHas('package', fn ($query) => $query->withTrashed()->where('type', 'reseller'))
|
||||
->where('active', true)
|
||||
->orderByDesc('expires_at')
|
||||
->first();
|
||||
|
||||
@@ -44,7 +44,7 @@ class TenantPackage extends Model
|
||||
|
||||
public function package(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
return $this->belongsTo(Package::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
|
||||
@@ -335,7 +335,7 @@ class CheckoutWebhookService
|
||||
protected function resolvePackageFromSubscription(array $data, array $metadata, string $subscriptionId): ?Package
|
||||
{
|
||||
if (isset($metadata['package_id'])) {
|
||||
$package = Package::find((int) $metadata['package_id']);
|
||||
$package = Package::withTrashed()->find((int) $metadata['package_id']);
|
||||
if ($package) {
|
||||
return $package;
|
||||
}
|
||||
@@ -344,7 +344,7 @@ class CheckoutWebhookService
|
||||
$priceId = Arr::get($data, 'items.0.price_id') ?? Arr::get($data, 'items.0.price.id');
|
||||
|
||||
if ($priceId) {
|
||||
$package = Package::where('paddle_price_id', $priceId)->first();
|
||||
$package = Package::withTrashed()->where('paddle_price_id', $priceId)->first();
|
||||
if ($package) {
|
||||
return $package;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ class CheckoutWebhookService
|
||||
$priceId = Arr::get($subscription, 'data.items.0.price_id') ?? Arr::get($subscription, 'data.items.0.price.id');
|
||||
|
||||
if ($priceId) {
|
||||
return Package::where('paddle_price_id', $priceId)->first();
|
||||
return Package::withTrashed()->where('paddle_price_id', $priceId)->first();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user