Skip to content

Commit 1b936dd

Browse files
committed
sort price actions by cost
1 parent c8ff2b6 commit 1b936dd

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

billing/src/Filament/App/Widgets/ProductWidget.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Boy132\Billing\Models\Customer;
77
use Boy132\Billing\Models\Order;
88
use Boy132\Billing\Models\Product;
9+
use Boy132\Billing\Models\ProductPrice;
910
use Filament\Actions\Action;
1011
use Filament\Actions\Concerns\InteractsWithActions;
1112
use Filament\Actions\Contracts\HasActions;
@@ -16,6 +17,7 @@
1617
use Filament\Schemas\Contracts\HasSchemas;
1718
use Filament\Schemas\Schema;
1819
use Filament\Widgets\Widget;
20+
use Illuminate\Database\Eloquent\Collection;
1921
use Illuminate\Support\Number;
2022

2123
class ProductWidget extends Widget implements HasActions, HasSchemas
@@ -31,7 +33,10 @@ public function content(Schema $schema): Schema
3133
{
3234
$actions = [];
3335

34-
foreach ($this->product->prices as $price) {
36+
/** @var Collection<int, ProductPrice> $prices */
37+
$prices = $this->product->prices()->orderBy('cost')->get();
38+
39+
foreach ($prices as $price) {
3540
$actions[] = Action::make('exclude_' . str_slug($price->name))
3641
->label($price->getLabel())
3742
->action(function () use ($price) {

0 commit comments

Comments
 (0)