【发布时间】:2020-08-31 02:46:14
【问题描述】:
当我想用参数实现导出数据时,我得到了堆栈,这是来自控制器的代码
public function export_byMonth(Request $request)
{
return Excel::download(new ProjectMSelected($request->m , $request->y), 'ProjectMonthly_'.$request->m.'_'.$request->y.'.xlsx');
}
注意 M 是月,Y = 是年
这是使用 maatwebsite/excel 导出的代码。
namespace App\Exports;
use App\table2;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
class ProjectMSelected implements FromView, WithHeadings
{
use Exportable;
public function __construct($m , $y)
{
$this->m = $m;
$this->y = $y;
}
public function headings(): array
{
return [
'Code Project' ,
'Name',
'Directorates',
'Division',
'Scope',
'Priority',
'Progress',
'%',
'Remarks',
'Plan',
'pdate',
'PM',
'CO PM',
];
}
public function view(): View
{
return view('report.excel.report_monthly_per_project', [
'project_array' => table2::whereRaw('YEAR(tgl_masuk) = ',$this->y ,'And Month(tgl_masuk) =', $this->m)->get()
]);
}
}
还是这样解析错误信息,如何解决?
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 (SQL: select * from `projectmonthlyview2` where Month(tgl_masuk) = YEAR(tgl_masuk) =)
【问题讨论】:
标签: mysql laravel laravel-5 eloquent