Picolé
Picolé
Explore posts from servers
FFilament
Created by Picolé on 2/7/2025 in #❓┊help
how to set the value of an input inside of a repeater?
So lets say I have a field inside a repeater and a repeater I want to change a value of an input inside of the repeater after another field inside of the repeater value changes I tried many approaches and the closest one to work was this one
public static function recalculateAllValueCustomers($livewire): void
{
$statePath = 'data';
$products = data_get($livewire, $statePath . '.products') ?? [];

// Retrieve parent fields from the state
$oceanFreight = (float) data_get($livewire, $statePath . '.ocean_freight', 0);
$tpFactor = (float) data_get($livewire, $statePath . '.value_customer_percentage', 0);

// Count only non-empty products (a product is non-empty if its "value" is not empty)
$nonEmptyProducts = collect($products)
->filter(fn($item) => isset($item['value']) && $item['value'] !== '')
->all();
$totalProducts = count($nonEmptyProducts) ?: 1;

// Update each product's "value_customer" in place
foreach ($products as $key => $product) {
if (empty($product['value'])) {
continue;
}
$unitaryPrice = (float) $product['value'];
$valueCustomer = ($oceanFreight / $totalProducts) + ($unitaryPrice * $tpFactor);
$formattedValue = number_format($valueCustomer, 2, '.', '');
// Only update if changed to avoid unnecessary refreshes
if (!isset($product['value_customer']) || $product['value_customer'] !== $formattedValue) {
$products[$key]['value_customer'] = $formattedValue;
}
}

// Update the Livewire state in place without re-indexing.
data_set($livewire, $statePath . '.products', $products);
}
public static function recalculateAllValueCustomers($livewire): void
{
$statePath = 'data';
$products = data_get($livewire, $statePath . '.products') ?? [];

// Retrieve parent fields from the state
$oceanFreight = (float) data_get($livewire, $statePath . '.ocean_freight', 0);
$tpFactor = (float) data_get($livewire, $statePath . '.value_customer_percentage', 0);

// Count only non-empty products (a product is non-empty if its "value" is not empty)
$nonEmptyProducts = collect($products)
->filter(fn($item) => isset($item['value']) && $item['value'] !== '')
->all();
$totalProducts = count($nonEmptyProducts) ?: 1;

// Update each product's "value_customer" in place
foreach ($products as $key => $product) {
if (empty($product['value'])) {
continue;
}
$unitaryPrice = (float) $product['value'];
$valueCustomer = ($oceanFreight / $totalProducts) + ($unitaryPrice * $tpFactor);
$formattedValue = number_format($valueCustomer, 2, '.', '');
// Only update if changed to avoid unnecessary refreshes
if (!isset($product['value_customer']) || $product['value_customer'] !== $formattedValue) {
$products[$key]['value_customer'] = $formattedValue;
}
}

// Update the Livewire state in place without re-indexing.
data_set($livewire, $statePath . '.products', $products);
}
with this approach, I think it replaces the whole products repeater, so it only work 1 time because the fields inside of the repeater lose it's reactivity how to actually change it?
3 replies
CDCloudflare Developers
Created by Picolé on 11/9/2023 in #general-help
Nameserver migrated to cloudflare from locaweb but flexible SSL not issued?
It just does not work at all, it says there's no SSL and then I get an infinite redirect loop
19 replies
CDCloudflare Developers
Created by Picolé on 10/30/2023 in #general-help
Cloudflare pages behind cloudflare zerotrust/vpn
Is it possible? should I create the application as Self-hosted or SaaS? The pages will only be accessible by users inside the team? they need WARP?
2 replies
FFilament
Created by Picolé on 5/17/2023 in #❓┊help
Sort with nulls last?
There's any way to create a custom sorting that will make NULLs stay last?
20 replies
FFilament
Created by Picolé on 5/1/2023 in #❓┊help
Filters like Excel Auto Filter
7 replies
FFilament
Created by Picolé on 4/8/2023 in #❓┊help
type('date') format?
There's any way to change it from the m/d/Y? really can't find it and the DatePicker::make does not allow typing, that's why im using type('date')
3 replies
FFilament
Created by Picolé on 3/27/2023 in #❓┊help
Dynamic Fields from php
Hello, Been trying to make dynamic fields from values that comes from the php model How am I supposed to be making dynamic fields? Considering this does not "disable" the File one making an error when using type as string?
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Hidden::make('type'), // <---- useless line
Forms\Components\TextInput::make('name')
->required()
->label('Nome')
->maxLength(255),
Forms\Components\FileUpload::make('value')
->label('Arquivo')
->hidden(fn (Config $record) => $record->type !== 'file')
->disabled(fn (Config $record) => $record->type !== 'file'),
Forms\Components\Textarea::make('value')
->label('Value')
->hidden(fn (Config $record) => $record->type !== 'string')
->disabled(fn (Config $record) => $record->type !== 'string'),
])
->columns(2)
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Hidden::make('type'), // <---- useless line
Forms\Components\TextInput::make('name')
->required()
->label('Nome')
->maxLength(255),
Forms\Components\FileUpload::make('value')
->label('Arquivo')
->hidden(fn (Config $record) => $record->type !== 'file')
->disabled(fn (Config $record) => $record->type !== 'file'),
Forms\Components\Textarea::make('value')
->label('Value')
->hidden(fn (Config $record) => $record->type !== 'string')
->disabled(fn (Config $record) => $record->type !== 'string'),
])
->columns(2)
]);
}
I don't know if this was supposed to be made with livewire, but I guess it should work already? the hide and disable work fine but really fails to submit
5 replies
FFilament
Created by Picolé on 3/3/2023 in #❓┊help
Anyone ever tried Filament with Bref? (serverless) Livewire corrupted error
I keep getting Livewire encountered corrupt data when trying to hydrate the [app.filament.resources.user-resource.pages.list-users] component. Ensure that the [name, id, data] of the Livewire component wasn't tampered with between requests Almost all actions give me this error eg: changing the number of itens per page Anyone ever had a problem like this? SESSION_DRIVER = cookies, CACHE_DRIVER = dynamodb Even the CSRF token was giving me errors (disabled it for livewire/filament/admin to test and it worked) Considering this may not fit in here but in Bref itself, I will deleted it in case nobody reply (no one had this problem)
7 replies
FFilament
Created by Picolé on 3/2/2023 in #❓┊help
If you had to process an uploaded excel to store into a model
Would you create the resource form as a single file upload where you process it and then save everything into the model (to show in the table later) or would you make a custom page or something else? trying to figure out the correct approach when using filament I don't think the resource form is the correct one because looks hard to change the values before saving and validating the excel to make sure everything is in there
4 replies