Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crudit Bundle Laravel Package

2lenet/crudit-bundle

Symfony bundle to rapidly build configurable CRUD back offices with SB Admin layout. Provides list views with pagination, sorting, actions, exports and batch ops, plus datasources, filters, menus, workflows, maps, markdown and Twig helpers.

View on GitHub
Deep Wiki
Context7

How to export data

Crudit adds an exporter that handles data export for multiple configurable formats.

By default, Crudit adds an "Export" button for all lists and will export index fields.

Usage

In your CrudConfig::getListActions, you can add the export action manually.

This is already configured by default.


public function getListActions(): array
{
    $actions[] = ListAction::new(
        "action.export",
        $this->getPath(CrudConfigInterface::EXPORT),
        Icon::new("file-export")
    )
        ->setModal("[@LleCrudit](https://github.com/LleCrudit)/modal/_export.html.twig")
        ->setConfig(
            [
                // you can change this part to put whatever you want
                "export" => [Exporter::CSV, Exporter::EXCEL],
            ]
        );
}

public function getFields($key): array
{
    if ($key === CrudConfigInterface::EXPORT) {
        return [
            Field::new(...)
        ];
    }

    // if EXPORT is not filled, INDEX is used instead
}

Crudit already comes with some exporters:

  • CsvExporter for csv files
  • ExcelExporter for xls files
  • PdfExporter for pdf files

Configuration

If you want to change the behaviour of the exporters, you can edit your CrudConfig::getExportParams.

public function getExportParams(string $format): ExportParams
{
    // $format contains Exporter::CSV, Exporter:EXCEL or whatever else you added
    return ExportParams::new()
        ->setFilename($this->getName())
        ->setSeparator(";");
}

Extending

You can add your own exporters.

Your exporter must implement Lle\CruditBundle\Contracts\ExporterInterface

  • getSupportedFormat: your format. It has to be then added in the "export" config of your ListAction (see above)
  • export: the actual export action. It must return a Response.

Example:

<?php


namespace App\Service\CustomExporter;


class CustomExporter implements ExporterInterface
{
    public function getSupportedFormat(): string
    {
        return "custom";
    }

    public function export(iterable $resources, ExportParams $params): Response
    {
        return new Response("Hello from custom export!");
    }
}

Don't forget to add action in your CrudConfig

ListAction::new()
    ->setModal("[@LleCrudit](https://github.com/LleCrudit)/modal/_export.html.twig")
    ->setConfig(
        [
            "export" => ["custom"],
        ]
    );

Crudit will automatically detect the exporters and complete the export form.

Pdf exporter

The PDF exporter can be personalized in the crud config:


public function getExportParams(string $format): ExportParams
    {
        $exportParams = parent::getExportParams($format);
        $params = $exportParams->getPdfParams();
        $params['locale'] = 'fr'
        $params['header-footer'] = [
                'header-left' => 'I am the page header',
                'footer-center' => 'Made with Crudit',
        ];
        $exportParams->setPdfParams($params);

        return $exportParams;
    }

The default values are:

[
    'title' => 'Export',
    'paper_size' => 9, //A4
    'orientation' => 'landscape',
    'decimal_separator' => ',',
    'thousands_separator' => '.',
    'locale' => 'fr',
    'header-footer' => [
        'header-left' => '',
        'header-center' => '',
        'header-right' => '',
        'footer-left' => '',
        'footer-center' => '',
        'footer-right' => '',
    ],
];

To customize the values, check the PhpSpreadsheet documentation,

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
bugban/php-sdk
littlerocket/job-queue-bundle
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php