iyaa
iyaa
FFilament
Created by iyaa on 3/27/2025 in #❓┊help
Export Action didn't Export A Defined Column
Im trying to export a table of temporary password into xlsx & csv. The migration and model is pretty simple model
class TemporaryPassword extends Model
{
use HasFactory;

protected $fillable = ['nis', 'plaintext_password'];
}
class TemporaryPassword extends Model
{
use HasFactory;

protected $fillable = ['nis', 'plaintext_password'];
}
and here's the exporter class
<?php

namespace App\Filament\Exports;

use App\Models\TemporaryPassword;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use OpenSpout\Common\Entity\Style\CellAlignment;
use OpenSpout\Common\Entity\Style\CellVerticalAlignment;
use OpenSpout\Common\Entity\Style\Color;
use OpenSpout\Common\Entity\Style\Style;

class TemporaryPasswordExporter extends Exporter
{
protected static ?string $model = TemporaryPassword::class;

public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('nis')
->label('NIS'),
ExportColumn::make('plaintext_password')
->formatStateUsing(fn($record) => $record->plaintext),
];
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your temporary password export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}

return $body;
}
}
<?php

namespace App\Filament\Exports;

use App\Models\TemporaryPassword;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use OpenSpout\Common\Entity\Style\CellAlignment;
use OpenSpout\Common\Entity\Style\CellVerticalAlignment;
use OpenSpout\Common\Entity\Style\Color;
use OpenSpout\Common\Entity\Style\Style;

class TemporaryPasswordExporter extends Exporter
{
protected static ?string $model = TemporaryPassword::class;

public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('nis')
->label('NIS'),
ExportColumn::make('plaintext_password')
->formatStateUsing(fn($record) => $record->plaintext),
];
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your temporary password export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}

return $body;
}
}
When I try to export, the field ID and nis exported to the xlsx & csv, but the plaintext_password didnt. I already tried to add protected $hidden = []; on the model yet it didnt work
1 replies
FFilament
Created by iyaa on 10/28/2024 in #❓┊help
Create Repeater Data on handleRecordCreation
Is there a way to create datas from Repeater on handleRecordCreation. Here's the case, I need to create a BuyingInvoice and BuyingInvoiceItem (it comes from the Repeater so there'll be some BuyingInvoiceItem ) on handleRecordCreation. Because I need to the id from the created BuyingInvoice and BuyingInvoiceItem s to create a StockUpdate that have the foreignId of BuyingInvoice and BuyingInvoiceItems Here's one of the BuyingInvoiceItem's data array
"item_id" => "1",
"price" => 10000,
"quantity" => "36",
"subtotal" => 360000,
];
"item_id" => "1",
"price" => 10000,
"quantity" => "36",
"subtotal" => 360000,
];
before I post this, I already try this way on the handleRecordCreation, well it works! BUT after the handleRecordCreation finished, it creates another BuyingInvoiceItems that comes from the Repeater
foreach ($buyingInvoiceItems as $buyingInvoiceItem) {
$buyingInvoice->buyingInvoiceItems()->create([
'item_id' => $buyingInvoiceItem['item_id'],
'quantity' => $buyingInvoiceItem['quantity'],
'price' => $buyingInvoiceItem['price'],
'subtotal' => $buyingInvoiceItem['subtotal'],
]);
foreach ($buyingInvoiceItems as $buyingInvoiceItem) {
$buyingInvoice->buyingInvoiceItems()->create([
'item_id' => $buyingInvoiceItem['item_id'],
'quantity' => $buyingInvoiceItem['quantity'],
'price' => $buyingInvoiceItem['price'],
'subtotal' => $buyingInvoiceItem['subtotal'],
]);
so the result on the Database there are two BuyingInvoiceItems with the exact same data just ith the different Id (because the data from Repeater created twice, the first one is on the handleRecordCreation that I made myself, and the other one is from outside the handleRecordCreation I guess?) How to solve this so that the BuyingInvoiceItems didnt duplicated
1 replies