Basic information

Repository
JaguarJack
Skill
export

About export

Generate Excel export class for CatchAdmin module.

export is an agent skill listed in the AddMCP.net directory, published by JaguarJack. Runtime: PHP. License: Apache-2.0. The repository has 940 GitHub stars. Source code is hosted on github.com. Related topics: admin, composer, elementplus, laravel, laravel-admin.

Overview

What is export?


name: export description: Generate Excel export class for CatchAdmin module.


Step 7: Generate Export Class

创建数据导出类。

File Location

modules/{Module}/Export/{Model}.php

Template

<?php

namespace Modules\{Module}\Export;

use Catch\Support\Excel\Export;

class {Model} extends Export
{
    protected array $header = [
        'ID', 'Name', 'Created At'
    ];

    public function array(): array
    {
        return \Modules\{Module}\Models\{Model}::query()
            ->select('id', 'name', 'created_at')
            ->get()
            ->toArray();
    }
}

Header Mapping

| Field | Header | |-------|--------| | id | ID | | name | Name | | email | Email | | status | Status | | created_at | Created At |

With Relationships

public function array(): array
{
    return {Model}::query()
        ->with('category')
        ->get()
        ->map(fn ($item) => [
            $item->id,
            $item->name,
            $item->category?->name ?? '-',
            $item->created_at,
        ])
        ->toArray();
}

Controller Usage

public function export(): mixed
{
    return {Model}::query()
        ->select('id', 'name', 'created_at')
        ->get()
        ->download(['ID', 'Name', 'Created At']);
}

31:T2764,

Comments

No comments yet

Be the first to share feedback about this listing. Sign in to leave a comment.

Sign In

Feedback 💬