2016-05-30 8 views
0

私は、Excelに登録して作成したいテーブルが2つあります。複雑な配列がLaravelのExcelにあります

event_invoice

id 
name 
invoice_value 
invoice_date 

invoiceモデル

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Invoice extends Model 
{ 
    // 
    protected $table = 'event_invoice'; 
    protected $primaryKey = 'Id'; 

    /* 
    * An invoice can has many payments 
    * 
    */ 

    public function duedates(){ 
     return $this->hasMany('App\invoiceduedates'); 
    } 

} 

invoiceduedate

id 
invoice_id 
date 
amountin 

duedatemodel

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class invoiceduedates extends Model 
{ 
    protected $table = 'invoiceduedates'; 


} 

だから、1枚の請求書を持つことができ、多くのduedates

私は任意の助けをいただければ幸いです

| name | invoice_value | invoice_date | due date1 | due amount1 | due date2 | due amount2 | due date3 | due amount3 | 
|------|---------------|--------------|------------|-------------|------------|-------------|------------|-------------| 
| A | 5000   | 30-01-2016 | 15-01-2016 | 2500  | 30-01-2016 | 04-11-1906 | null  | null  | 
| B | 8000   | 02-05-2016 | 15-02-2016 | 8000  | null  | null  | null  | null  | 
| C | 10000   | 03-05-2016 | 15-05-2016 | 5000  | 19-05-2016 | 2500  | 19-05-2016 | 2500  | 

この形式では、Excelで表示したい

ありがとう

+1

これは単なる基本的なループとの行を書いて、Laravelとはあまりありません、あなたは自分のデータを収集し、Excelファイルでそれらを記述する必要がこの時点から

ファイル。それで、私はcsvファイルを書くことをお勧めしたいと思います。 – Devon

+0

このLaravelパッケージを使って作業を行うことができます** maatwebsite/excel ** http://www.maatwebsite.nl/laravel-excel/docs/getting-started – TheFallen

答えて

0

問題はLaravel自体とは関係ありません。

あなたがしたいのは、Composerを使用してLaravelプロジェクトに追加できるPHPExcelなどのExcelファイルを操作できるライブラリを使用することです。

$invoices = Invoice::with('duedates')->get(); 

foreach ($invoices as $invoice) 
{ 
    // ... Write the basic fields such as "name" or "invoice_value" 

    $dueDateCount = 0; 
    foreach ($invoice->duedates as $dueDate) 
    { 
     // ... Write the specific invoice dates using $dueDateCount to specify the ID 

     $dueDateCount++; 
    } 
} 
+0

実際に '$ invoices = Invoice :: with ( 'duedates') - > get(); '私は請求書の詳細を取得しますが、リレーションシップはそれが表示されていないことを示しています... – Vikram

+0

おそらく十分な深さを持たない' var_dump'設定 – AntoineB

関連する問題