Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Excel Maatwebsite的索引列_Excel_Laravel_Export_Maatwebsite Excel - Fatal编程技术网

Laravel Excel Maatwebsite的索引列

Laravel Excel Maatwebsite的索引列,excel,laravel,export,maatwebsite-excel,Excel,Laravel,Export,Maatwebsite Excel,我想使用laravel excel maatwebsite将数据从数据库导出到excel,问题是我不知道如何将索引列添加到excel文件中。例如,我希望excel中的数据来自以下外观: Name Birthdate Rudolf 1990-05-20 Andi 1991-11-01 Harry 1993-03-25 为此: No Name Birthdate 1 Rudolf 1990-05-20

我想使用laravel excel maatwebsite将数据从数据库导出到excel,问题是我不知道如何将索引列添加到excel文件中。例如,我希望excel中的数据来自以下外观:

Name        Birthdate
Rudolf      1990-05-20
Andi        1991-11-01
Harry       1993-03-25
为此:

No      Name        Birthdate
1       Rudolf      1990-05-20
2       Andi        1991-11-01
3       Harry       1993-03-25
这是我的模型:

namespace App\Exports;

use App\user;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

class userExport implements FromQuery, WithHeadings, ShouldAutoSize{
    use Exportable;

    public function headings(): array{
        return [
            'Tanggal',
            'Nomor Permohonan',
            'Nama Pemohon',
        ];
    }
    public function __construct(int $status)
    {
        $this->status = $status;
    }

    public function query(){
        $date   = \Carbon\Carbon::now()->toDateString() ;
        return user::query()->select('name','birthdate')->where('status', $this->status)->whereDate('date',$date);
    }
}
我在控制器中的功能:

public function export() {
        return (new userExport(1))->download('user.xlsx');
}

我该怎么做?帮帮我。谢谢。

您必须在查询中尝试选择id user::query()->选择('id','name','birthdate')

将其添加到
公共函数查询中怎么样?