2016-04-09 24 views
0

最近この問題が発生しました。 Laravel Excelを使用してデータベースデータをExcelにエクスポートします。私はチュートリアルのリンクにコードをコピーしましたが、残念ながらそれは私にとっては役に立ちません。そして、私はlaravelが構成を上回るようにすべてを準備していると思います。これを解決する手助けができますか?ありがとう。ここに私のコードがあります。Laravel ExcelがLaravelで動作しない5.2

私のコントローラメソッド

public function exportInventory(){ 

    $products = Product::all(); 

    Excel::create('products', function($excel) use($products){ 

    $excel->sheet('Excel sheet', function($sheet) use($products){ 

     $sheet->fromArray($products); 
     $sheet->setOrientation('landscape'); 

    }); 

    })->export('xls'); 

} 

マイモデル

<?php 

namespace App\Product; 

use Illuminate\Database\Eloquent\Model; 

class Product extends Model 
{ 

// 
    protected $fillable = ['pharmaceutical','description','unit','quantity','price','amount','type','packaging','lot','expiry_date_month']; 
    protected $guarded = ['price']; 
} 

私のデータベース表

enter image description here

エラー enter image description here

+0

ProductControllerの76行目はどれですか? –

+0

}} - > export( 'xls'); – Eli

+0

これで助けてください... – Eli

答えて

1

変更してコード: $製品=製品::すべての(); 〜toArray(); $ products = Product :: all() - > toArray();

+0

それはあなたを助けましたか? –

関連する問題