다음 Laravel 튜토리얼 칼럼에서는 Laravel-excel3.1의 가장 기본적인 사용법을 소개하겠습니다. 모든 분들께 도움이 되길 바랍니다!
공식 홈페이지: https://docs.laravel-excel.com
Route::get('/export', [OrderController::class, 'export']);
컨트롤러 전달
public function export(Request $request): BinaryFileResponse{ return Excel::download(new OrderExport($request->get('status', -1)), 'order.xlsx');}
비즈니스 코드
<?php namespace App\Exports; use App\Models\Order; use Illuminate\Support\Collection; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithColumnFormatting; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; /** * 派单导出 */ class OrderExport implements FromCollection, WithHeadings, WithColumnFormatting, WithMapping { public $status; //接受参数 public function __construct(int $status) { $this->status = $status; } /** * 数据源 * @return Collection */ public function collection(): Collection { $query = Order::query(); if ($this->status != -1) { $query->where('status', $this->status); } return $query->get(); } /** * 自定义表头 * @return string[] */ public function headings(): array { return [ '编号', '创建人', '中队长', '人员', '名称', '备注', '状态', '创建时间', '更新时间' ]; } /** * 设置单元格时间格式 * @return array */ public function columnFormats(): array { return [ 'H' => NumberFormat::FORMAT_DATE_YYYYMMDD, 'I' => NumberFormat::FORMAT_DATE_YYYYMMDD, ]; } /** * 自定义数据列 * @param mixed $row * @return array */ public function map($row): array { return [ $row->id, $row->founder->name ?? '无', $row->squadron->name ?? '无', $row->player->name ?? '无', $row->name, $row->remark ?: '无', $this->statusMap($row->status), Date::dateTimeToExcel($row->created_at), Date::dateTimeToExcel($row->updated_at), ]; } /** * 状态转化 * @param $status * @return string */ public function statusMap($status): string { switch ($status) { case 0: $statusText = '待处理'; break; case 1: $statusText = '处理中'; break; case 2: $statusText = '待审核'; break; case 3: $statusText = '已完成'; break; default: $statusText = '未知'; } return $statusText; } }
을 정의합니다. 관련 추천: 최신 5개 Laravel 비디오 튜토리얼
🎜 🎜🎜 🎜
위 내용은 Laravel-excel3.1의 기본 사용법에 대한 간략한 분석의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

LARAVEL10INTRODICESEREVERALKEYFEATERESTERETHANCEBEDEVENCENTMENT.1) LazyCollectionsallowEctiversityProcessingoflargedAgestoutSwithoutlakestougleswithoutlakeStiSwithoutloUgentswithoutloWeDAtSwithOUdlingAllRecordsIntomemory.2) The'Make : Model 및 Mightration 'and Mighting'and Mighting 'and Megigation'ArtisAncommandSimplifiesmomodelSandmagrations.3) Integration

laravelymigrations는 eTheystreamlinedevelopment, ensereconsconsencyacrossenvironments 및 simplifycollaborationanddeployment.1) theavergrammationmanagementofdatabaseSchemachanges, rowingerrors.2) MigrationsCanbeverSioncontrolled, ensurin

예, laravelmigrationisworthsing.itsimplifiesDatabaseSchemamanagemanagement, EnhanceScollaboration 및 provostversionControl.useitForstructured, 효율적인 개발.

SoftDeletesInlaravelImpActPerformanceByplicatingQueriesandincreasingStorageneeds.tomitigateSeissues : 1) INDEXTHEDETEDEDEDED_ATCOLUMNTOSPEEDUPQUERIES, 2) useEgerLoadTuceQueryCount 및 3) 정기적으로 클레어 업 소프트-드레인드 리코드 스토 파이어를 유지합니다

laravelmigrationsearebeneficialforversontrol, 협업 및 프로모션 gooddevelopmentpractices.1) theavallingandrollingbackdatabaSechanges.2) MigrationsEnsUreTeAmmebers'SchemasStaySynchronized.3) theencouroughoughoughdatabovase innandeasyre

Laravel의 Soft Deletion 기능은 실제 삭제보다는 레코드를 표시하여 데이터를 보호합니다. 1) SoftDeletEstrait 및 Deleted_at 필드를 모델에 추가하십시오. 2) delete () 메소드를 사용하여 삭제를 표시하고 복원 () 메소드를 사용하여 복원하십시오. 3) 쿼리시 소프트 삭제 레코드를 포함시키기 위해 withTrashed () 또는 coneseTrashed ()를 사용하십시오. 4) 성능을 최적화하기 위해 일정 시간을 초과 한 소프트 삭제 레코드를 정기적으로 청소하십시오.

laravelmigrationseversioncontrolfordatabaseSchemas.

laravelmigrationsmayfailtorollbackduetodataintegritysues, foreignkeyconstraints, orirreversibleactions.1) dataintegrityScanoccurifamigrationaddsdatathatcan'tBeontundone, likeacolumnwithadefaultValue.2) 외국 keycanstraintscanpreventrollsofrelatio


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구