我的代码出了什么问题,我尝试使用 Laravel 框架导出数据表。下载的文件内容为空。StockModel.phpnamespace App; use Illuminate\Database\Eloquent\Model; class Stock extends Model { protected $table = 'stock_tb'; protected $primaryKey = 'id'; protected $fillable = ['stock_id', 'input_date', 'quantity']; }管理控制器.phpuse Excel;use App\Stock;use App\Exports\StockExport;class adminController extends Controller { public function __construct() { } public function printStockReport(){ return Excel::download(new StockExport('07/01/2020'), 'ado.xlsx'); }StockExport.phpnamespace App\Exports;use App\Stock;use Maatwebsite\Excel\Concerns\FromQuery;class StockExport implements FromQuery{ protected $id; public function __construct($date_var) { $this->date = $date_var; } public function query() { return Stock::query()->where('input_date', $this->date)->get(); } }路由器Route::get('admin/printStockReport', 'adminController@printStockReport');仅供参考:我在 RDBMS 上运行 SQL 代码,条件输入日期为07/01/2020。它返回 129 条记录。谢谢
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报
0/150
提交
取消