Custom button

Hello Guys.
I'v been struglling the whole day to get this work :

I have a 'Purchase' resource where I enter multiple quotes of companies.
I'v created a button above the form like he attached image.



where :
public static function generateSelectedWinnerBid(Get $get, Set $set)
    {
        $purchaseId = $get('id'); // Assuming the form has the purchase ID

        $purchase = Purchase::find($purchaseId);

        if ($purchase) {
            $quote = $purchase->quotes()->where('has_confirmed', true)->orderBy('id', 'desc')->first();

            if ($quote) {
                $set('awarded_company', $quote->company_name);
                $set('amount', $quote->amount);
                $set('amount_letters', self::convertNumberToWords($quote->amount));
    
                // dd('Form Values Set:', [
                //     'awarded_company' => $quote->company_name,
                //     'amount' => $quote->amount,
                //     'amount_letters' => self::convertNumberToWords($quote->amount),
                // ]); // Debug: Check form values set

                Notification::make()
                    ->title('Form fields have been populated successfully.')
                    ->success()
                    ->send();
            } else {
                Notification::make()
                    ->title('No confirmed quote found for this purchase.')
                    ->danger()
                    ->send();
            }
        } else {
            Notification::make()
                ->title('Purchase not found.')
                ->danger()
                ->send();
        }
    }


I even dd() the fetching to see the results, and it's showing the data properly, BUT it's not populating the inputbox I needed :

$set('awarded_company', $quote->company_name);
$set('amount', $quote->amount);
$set('amount_letters', self::convertNumberToWords($quote->amount));


is there something i'm missing ??

Thank You
Screenshot_2024-07-21_184548.png
Was this page helpful?