Tôi đang cố nhập dữ liệu vào MySQL từ tệp Excel. Bảng của tôi có 2 khóa ngoại project_id và site_id khi nhập. Tôi đang chọn 2 trường này từ danh sách thả xuống trong Chế độ xem của mình. Có cách nào để tôi có thể ánh xạ 2 trường này vào bộ sưu tập nhập của mình không?
Bộ sưu tập
namespace App\Imports; use App\Proposal; use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithHeadingRow; class ProposalsImport implements ToModel, WithHeadingRow { public function model[array $row] { return new Proposal[[ 'building' => $row['building'], 'floor' => $row['floor'], 'area' => $row['area'], 'room' => $row['room'], 'luminaire' => $row['luminaire'], 'actual_qty' => $row['actual_qty'], 'installed_qty' => $row['installed_qty'], ]]; } }
Bộ điều khiển
public function import[] { Excel::import[new ProposalsImport, 'proposals.xlsx']; }
Khung nhìn
@extends['projectmanagement/proposals.base'] @section['action-content'] @push['custom_scripts'] @endpush @endsection@if [session['status']]{{ session['status'] }}×@endif{{ csrf_field[] }}Project NameSelect Project @foreach [$projects as $project] {{ $project->project_name }} @endforeach @if [$errors->has['project_id']] {{ $errors->first['project_id'] }} @endif
Site NameSelect Site @foreach [$sites as $site] {{ $site->site_name }} @endforeach @if [$errors->has['site_id']] {{ $errors->first['site_id'] }} @endif
Proposal File@if [$errors->has['proposal_file']] {{ $errors->first['proposal_file'] }} @endif
Upload Proposal
Làm cách nào để xuất dữ liệu đã chọn sang tệp excel bằng laravel?
Có 9 bước đơn giản để làm theo. .
Cài đặt dự án laravel mới
Cấu hình chi tiết cơ sở dữ liệu và mô hình
Cài đặt gói maatwebsite/excel
Tạo tuyến đường
Tạo lớp nhập để nhập dữ liệu
Tạo một lớp xuất để xuất dữ liệu
Tạo bộ điều khiển
Tạo các tập tin lưỡi / xem
Làm cách nào tôi có thể truyền tham số trong laravel Excel?
Làm tham số
. using the second parameter inside the loadView[] method.
Làm cách nào để sử dụng excel nhanh trong laravel?
Cài đặt fast-excel bằng trình soạn nhạc yêu cầu rap2hpoutre/fast-excel
Tạo một dataTable lớp php artisan datatables. tạo người dùng
Điều chỉnh UsersDataTable khi cần
Đặt thuộc tính $fastExcel = true
Làm cách nào để đặt độ rộng cột trong Excel laravel?
# Kích thước ô .
Đặt chiều rộng cột. Để đặt độ rộng cột, hãy sử dụng ->setWidth[$cell, $width]. .
Đặt chiều cao hàng. Để đặt chiều cao hàng, hãy sử dụng ->setHeight[$row, $height]. .
Đặt kích thước ô. Để đặt kích thước ô, hãy sử dụng ->setSize[$cell, $width, $height]