FilamentF
Filament3y ago
3 replies
dongoldstein

Saving the received data line by line

Hello, I want to save the data (stock) I received with TextArea to the database.
One stock data is entered in each row, and each data should be recorded in the database as a row.
For example;
TextArea[
stock1
stock2
stock3
]

Database;
ID - stock_detail...
1 - stock1
2 - stock2
3 - stock3

how can I do that? I didn't see it in the documentation.
Solution
Fixed;

CreateRecord File:

    protected function handleRecordCreation(array $data): Model
    {
        $stocks = explode(PHP_EOL, $data['stock_detail']);

        unset($data["stock_detail"]);

        $stockData = [];

        foreach ($stocks as $stock){

            $data["stock_detail"] = $stock;
            $tempData = static::getModel()::create($data);
            $stockData[] = $tempData;

        }

        return $stockData[0];
    }
Was this page helpful?