Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/Filament/Resources/Plans/PlanResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@ public static function form(Schema $schema): Schema
->maxLength(191),
])->columns(2),
Section::make('Plan Status')
->description('Make the plan default or active/inactive')
->description('Make the plan default or active/inactive and set the sort order')
->schema([
Toggle::make('active')
->required(),
Toggle::make('default')
->required(),
TextInput::make('sort_order')
->integer()
->default(0)
->minValue(0)
->required(),
])->columns(2),
Section::make('Associated Role')
->description('When the user subscribes to this plan, what role should they be assigned?')
Expand All @@ -108,6 +113,9 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('name')
->searchable(),
TextColumn::make('sort_order')
->numeric()
->sortable(),
TextColumn::make('role_id')
->numeric()
->sortable(),
Expand All @@ -122,6 +130,7 @@ public static function table(Table $table): Table
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->defaultSort('sort_order')
->filters([
//
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class="mx-auto mt-12 mb-2 w-full max-w-6xl md:my-12" x-cloak>

<div class="flex flex-col flex-wrap lg:flex-row lg:space-x-5">

@foreach(Wave\Plan::where('active', 1)->get() as $plan)
@foreach(Wave\Plan::getActivePlans() as $plan)
@php $features = explode(',', $plan->features); @endphp
<div
{{-- Say that you have a monthly plan that doesn't have a yearly plan, in that case we will hide the place that doesn't have a price_id --}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('plans', function (Blueprint $table) {
$table->integer('sort_order')->default(0);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('plans', function (Blueprint $table) {
Schema::dropColumns('plans', 'sort_order');
});
}
};
2 changes: 1 addition & 1 deletion wave/src/Http/Livewire/Billing/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function switchPlan(Plan $plan)
public function render()
{
return view('wave::livewire.billing.checkout', [
'plans' => Plan::where('active', 1)->get(),
'plans' => Plan::getActivePlans(),
]);
}
}
4 changes: 2 additions & 2 deletions wave/src/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public static function getActivePlans()
if (app()->bound('cache')) {
try {
return Cache::remember('wave_active_plans', 1800, function () {
return self::where('active', 1)->with('role')->get();
return self::where('active', 1)->orderBy('sort_order')->with('role')->get();
});
} catch (Exception $e) {
// Fallback to direct query if cache fails
}
}

return self::where('active', 1)->with('role')->get();
return self::where('active', 1)->orderBy('sort_order')->with('role')->get();
}

/**
Expand Down