깃주소
사용법 동영상
사이트 메뉴얼
설치 메뉴
컴포저 설치
1 | composer require maatwebsite/excel | cs |
구성 공개
1 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" | cs |
1. export명령어로 파일을 생성 (파일은 app/Exports/BoardSearchExport 생성됨)
1 | php artisan make:export BoardSearchExport --model=BoardSearchExport | cs |
2. 받을 인자와 쿼리문을 작성해준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?php namespace App\Exports; use App\Product; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\Exportable; class BoardsearchExport implements FromQuery { /** * @return \Illuminate\Support\Collection */ use Exportable; public function __construct(int $year, string $board_name_search) { //dd($year,$boardname); $this->year = $year; $this->boardname = $board_name_search; } public function query() { return Product::query()->whereYear('created_at', $this->year)->where('board_name', $this->boardname); } } | cs |
3. SpcsController.php
1 2 3 4 5 6 7 8 9 | namespace App\Http\Controllers; use App\Exports\BoardsearchExport; use App\Exports\BoardsearchExportView; use Illuminate\Http\Request; use App\Product; use App\Project; use App\Works; use Maatwebsite\Excel\Facades\Excel; | cs |
1 2 3 4 | public function export($board_name_search) { return Excel::download(new BoardsearchExport(2020,$board_name_search), 'qwer.xlsx'); } | cs |
4. web.php
1 2 | #excel export Route::get('/bobo/{board_name_search?}','SpcsController@export')->middleware('lv2')->name('bobo'); // | cs |
5. 해당 블레이드파일에 버튼을 삽입한다.
1 2 3 | <div class="column"> <div > <a href="/bobo/{{ $board_name_search }}" class="ui teal button">엑셀파일 다운로드</a></div> </div> | cs |
테이블 파일 인크루드
1 | @include('main.table', $products) | cs |
table.blaed.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <table class="ui twelve column celled table"> <thead> <tr> <th>ID</th> <th>시리얼번호</th> <th>보드명</th> <th>생산일</th> <th>출하일</th> <th>출하내역</th> <th>불량</th> <th>불량내용</th> <th>타입</th> <th>인수자</th> <th>인계자</th> <th>메모</th> </tr> </thead> <tbody> @foreach($products as $product) <tr> <td>{{ $product->id }}</td> <td> <form action="/serialNameSearch" method="GET"> <input type="hidden" name="serial_name" value="{{ $product->serial_name }}" > <button style=" background:none;border:none; margin:0px;cursor: pointer;">{{ $product->serial_name }}</button> </form> </td> <td> <form action="/pbas/" method="GET"> <input type="hidden" name="board_name" value="{{ $product->board_name }}" > <button style=" background:none;border:none; margin:0px;cursor: pointer;">{{ $product->board_name }}</button> </form> </td> <td>{{ $product->product_date }}</td> <td>{{ $product->shipment }}</td> <td>{{ $product->shipment_daily }}</td> <td>{{ $product->faulty }}</td> <td>{{ $product->remarks }}</td> <td>{{ $product->type }}</td> <td>{{ $product->receiver }}</td> <td>{{ $product->ship_user }}</td> <td>{{ $product->note }}</td> </tr> @endforeach </tbody> </table> | cs |
6. 브라우저에서 해당버튼을 누르면 엑셀파일이 다운로드 받아진다.
역순으로 나왔지만 잘 추출된다.
'라라벨 > 라이브러리' 카테고리의 다른 글
라라벨 마크다운 문서작성 라이브러리 (0) | 2020.12.26 |
---|---|
디버그바 설치 (0) | 2020.03.04 |
laravel log-viewer 설치 (0) | 2019.08.31 |
laravel sweet-alert 설치 경고창 설정 (0) | 2019.08.30 |
라라벨 회원계정 사진올리기 (0) | 2019.07.13 |