我最近刚刚被这个问题困住了。使用 Laravel Excel 将我的数据库数据导出到 Excel。我刚刚复制了教程链接上的代码,但不幸的是它对我不起作用。而且我想我已经为 laravel excel 配置设置了一切。你能帮我解决这个问题吗?谢谢。这是我的代码。
我的控制器方法
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'];
}
我的数据库表