#Setting default value for Checkbox (forms) is not working

6 messages · Page 1 of 1 (latest)

queen mantle
#

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;
                    })

junior cloud
cinder blaze
#

Note that these defaults are only used when the form is loaded without existing data

queen mantle
queen mantle