我实现了maatwebiste(向excel导出)并试图对其进行改进。我只想在Excel中显示日期,而不以年/月/日的格式显示hh:mm:ss
所以我尝试了这种映射,但是遇到错误“找不到类'App \ Exports \ Date'”,但是我已经导入了WithMapping类。
任何提示为什么我会收到此错误?
PostExport
use App\Post;
use Illuminate\Contracts\Support\Responsable;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromQuery;
// use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
class PostExport implements FromQuery, Responsable, WithMapping, WithHeadings
{
public function map($post): array
{
return [
Date::dateTimeToExcel($post->created_at),
];
}
public function query()
{
return Post::select('title','message','created_at','updated_at')
->whereMonth('created_at',$this->to_month)
->whereDay('created_at',$this->to_day)
->whereyear('created_at',$this->to_year);
// return Post::query()->whereMonth('created_at',$this->to_month)
// ->whereDay('created_at',$this->to_day)
// ->whereyear('created_at',$this->to_year);
}