从数据库导出到xls(laravel 5)

public function export(){ view('tester'); $assignments = DB::table('assignments') ->join('projects', 'assignments.project_id', '=', 'projects.id') ->join('people', 'assignments.person_id', '=', 'people.id') ->join('tasks', 'assignments.id', '=', 'tasks.assignment_id') ->select('assignments.*', 'projects.name','people.firstname','people.lastname', 'tasks.description','tasks.hours_spent') ->get(); Excel::create('projects', function($excel) use($assignments) { $excel->sheet('Sheet 1', function($sheet) use($assignments) { $sheet->fromArray($assignments); }); })->export('xls'); } 

当我点击导出到xls

  <form class="form-horizontal" role="form" method="POST" action="{{action('ReportController@export')}}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <h4>Task Report</h4> <button type="submit" class="btn btn-info btn-sm pull-right" style="margin-right: 10px"> Export to XLS format </button> 

错误是DefaultValueBinder.php中的ErrorException第65行:类stdClass的对象无法转换为string。 请帮我解决这个问题。

试试这个简单而简单的: –

 $assignments = json_decode( json_encode($assignments), true); 
 $filename = "Report-".date('dm-Y').'_'.time(); Excel::create($filename, function($excel)use($record) { $excel->sheet('Sheet 1', function($sheet)use($record) { $sheet->loadView('view', compact(array('record'))); $sheet->setOrientation('portrait'); }); })->export('xls'); exit(); 

也可以在<table>查看和显示logging,但是这个视图不会调用任何布局部分

如果我使用DB来获取数据,我得到错误….

DefaultValueBinder.php中的ErrorException:第65行:类stdClass的对象无法转换为string

 $ret = Excel::create('statsExtract', function($excel) { $data = DB::table('thrps')->get(); $excel->sheet('stats', function($sheet) use($data) { $sheet->fromArray($data); }); })->download('xls'); 

如果我提取使用雄辩模型…..它的作品….

 $ret = Excel::create('statsExtract', function($excel) { $data = Thrp::all(); $excel->sheet('stats', function($sheet) use($data) { $sheet->fromArray($data); }); })->download('xls'); 

但是,如果我尝试添加 – > leftJoin语句,我得到一个错误,leftJoin不存在….