Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vinParker's avatar

Download a generated CSV file after an Action

Hi Everybody ! I have to make an Action on a model (with Nova 4). It's a e-shop, and my client want to generate a CSV file with all products of all orders to prepare.

I started:

public function actions(NovaRequest $request)
    {
        return [
            Actions\PrepareProducts::make()
                ->standalone()
                ->confirmText('Define the start and end dates for generating the picking file.')
                ->confirmButtonText('Generate')
                ->cancelButtonText('Cancel'),
        ];
    }

I create my action (nova make:action):

public function handle(ActionFields $fields, Collection $models)
    {
         $startDate = $fields->start_date;
         $endDate = $fields->end_date;

         UtilitiesController::prepareProducts($startDate, $endDate);
         return Action::message("Traitement effectué avec succès !");
    }

    public function fields(NovaRequest $request)
    {
        return [
            Date::make('Date de début', 'start_date')->rules('required')->help('A 00h00'),
            Date::make('Date de fin', 'end_date')->rules('required')->help('A 23h59'),
        ];
    }

And my function is for now just:

 public static function prepareProducts($start, $end)
    {
      // For tests
        $orders = Order::get();
        return $orders;
    }

Is it possible to create a CSV with this query result, and start downloading?

Thanks a lot! Vincent

0 likes
0 replies

Please or to participate in this conversation.