diff --git a/.vuepress/3.1.js b/.vuepress/3.1.js index 9e41f2a..049d48a 100644 --- a/.vuepress/3.1.js +++ b/.vuepress/3.1.js @@ -35,6 +35,7 @@ module.exports = [ 'queued', 'multiple-sheets', 'mapping', + 'headings', 'column-formatting', 'settings', 'drawings', diff --git a/3.1/exports/headings.md b/3.1/exports/headings.md new file mode 100644 index 0000000..9c7e283 --- /dev/null +++ b/3.1/exports/headings.md @@ -0,0 +1,46 @@ +# Headings + +[[toc]] + +## Adding a heading row + +A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added +as very first row of the sheet. + +```php + +use Maatwebsite\Excel\Concerns\FromQuery; +use Maatwebsite\Excel\Concerns\WithHeadings; + +class InvoicesExport implements FromQuery, WithHeadings +{ + public function headings(): array + { + return [ + '#', + 'User', + 'Date', + ]; + } +} +``` + +If you need to have multiple heading rows, you can return multiple rows from the `headings()` method: + + +```php + +use Maatwebsite\Excel\Concerns\FromQuery; +use Maatwebsite\Excel\Concerns\WithHeadings; + +class InvoicesExport implements FromQuery, WithHeadings +{ + public function headings(): array + { + return [ + ['First row', 'First row'], + ['Second row', 'Second row'], + ]; + } +} +``` \ No newline at end of file diff --git a/3.1/exports/mapping.md b/3.1/exports/mapping.md index 295035c..39706a5 100644 --- a/3.1/exports/mapping.md +++ b/3.1/exports/mapping.md @@ -65,49 +65,6 @@ class InvoicesExport implements FromQuery, WithMapping } ``` -## Adding a heading row - -A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added -as very first row of the sheet. - -```php - -use Maatwebsite\Excel\Concerns\FromQuery; -use Maatwebsite\Excel\Concerns\WithHeadings; - -class InvoicesExport implements FromQuery, WithHeadings -{ - public function headings(): array - { - return [ - '#', - 'User', - 'Date', - ]; - } -} -``` - -If you need to have multiple heading rows, you can return multiple rows from the `headings()` method: - - -```php - -use Maatwebsite\Excel\Concerns\FromQuery; -use Maatwebsite\Excel\Concerns\WithHeadings; - -class InvoicesExport implements FromQuery, WithHeadings -{ - public function headings(): array - { - return [ - ['First row', 'First row'], - ['Second row', 'Second row'], - ]; - } -} -``` - ## Prepare rows If you need to prepare rows before appending these rows to sheet, you can add method `prepareRows` to your export class. This method will be called before flattening the query output and calling `map()`.