FilamentF
Filament5mo ago
john

Setting default value for Checkbox (forms) is not working

I am trying to set a default value for a Checkbox. Basically I am trying to get a value from the database and then based on a specific condition, check/uncheck the box automatically.

Here is the code snippet:

Checkbox::make('subscription_never_ends')
                    ->label('Subscription never ends')
                    ->reactive()
                    ->default(function (OfflinePayment $record) {
                        $stripeId = 'offline_' . $record->transaction_id;
                        $subscription = DB::table('subscriptions')
                            ->where('stripe_id', $stripeId)
                            ->first();

                        Log::info($subscription);

                        return $subscription && $subscription->ends_at === null;
                    })
Was this page helpful?