I got stack when i want to implement export data with parameters, this is the code from controller
public function export_byMonth(Request $request)
{
return Excel::download(new ProjectMSelected($request->m , $request->y), 'ProjectMonthly_'.$request->m.'_'.$request->y.'.xlsx');
}
Note M is Month and Y = is Year
and this is the code for export using 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()
]);
}
}
it's still parsing the error message like this, how to solve the error ?
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) =)
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire