F
Filament13mo ago
ashar

hi,

i have two fields Forms\Components\Select::make('account_id')->options((new ExpenseService())->getAccounts())->placeholder('Please select a debit account'),
Forms\Components\Hidden::make('name')->default(), how can i use llive() on account so what ever the account is, the name defuault column gets updated with it
9 Replies
ashar
asharOP13mo ago
yes i want when account_id fields is selected , its name should be assigned as default in name field @Shaung Bhone
Shaung Bhone
Shaung Bhone13mo ago
You need to read doc first
ashar
asharOP13mo ago
yes on it
Dennis Koch
Dennis Koch13mo ago
Instead of using a hidden field I guess it might be better to use the mutateDataBeforeCreate() hook and pull the data via the id from the DB there. Hidden fields are on the client side and can be manipulated
ashar
asharOP13mo ago
i am doing this already protected function mutateFormDataBeforeCreate(array $data): array { $data = $this->data; $data has my data and within it there is a array . when im updating , it doesnt fetches the array from $data and im unable to update those fields . SO for now i am updating it on default in the form . @Dennis Koch so this is the reason i want that the form name should be set as defualt account_id name @Dennis Koch
Dennis Koch
Dennis Koch13mo ago
What do you mean „it doesn’t fetch the array from $data“? If you want to make changes you need to change that array and return it. You put that method on the CreatePage?
ashar
asharOP13mo ago
dd($data) showing array:3 [▼ // app/Filament/Resources/ExpenseResource/Pages/CreateExpense.php:27 "name" => "Laurel Conner" "description" => "Veritatis velit lau" "voucherDetails" => array:1 [▶] ] you see i have array vcoucherDetilas in it but when i update record in mutate function foreach ($data['voucherDetails'] as &$voucherDetail) { $voucherDetail = array_merge($voucherDetail, [ 'account_id' => $account, 'voucherable_type' => Account::class, 'created_by' => Auth::id(), 'voucherable_id' => $account, 'quantity' => 1, ]); } its not updating the data in voucherDetail. so for now i was setting default values based on account_id for name . The rest i have set to default @Dennis Koch its was giving eror no default value for etc . coz it was going null so the value i want im storing it in default for now . now can you help ? @Dennis Koch
Dennis Koch
Dennis Koch13mo ago
I don't know whether pass by reference works here with array data. foreach ($data['voucherDetails'] as &$voucherDetail) { Did you verify the modified data at the end of the method? Also please look at #✅┊rules on how to format code. It's hard to read your messages otherwise.
Want results from more Discord servers?
Add your server