May 19, 2022
0
Level 1
Livewire strange excel not exporting on select all
Im facing a strange behavior when i select all entries to export excel document is blank, the weird is that working on local server and also worked for few months on my VPS server, but now i cant understant what happened and doesnt export the entries, see the code:
public function export($exl)
{
return Excel::download(new ChargesExport ($this->getSelected()),'Charges.' . $exl);
}
public function updatedselectAll($value)
{
if ($value) {
$this->selected= charge::query();
if($this->search){
$this->selected= $this->selected->search($this->search)
->select(\DB::raw('charges.*,SUM(taskscharges - payment) as balance','customers.name as custname'))
->join('customers', 'charges.customer_id', '=', 'customers.id')
->groupBy('id')
->pluck('id');
}else{
$this->selected= $this->selected->select(\DB::raw('charges.*,SUM(taskscharges - payment) as balance','customers.name as custname'))
->join('customers', 'charges.customer_id', '=', 'customers.id')
->groupBy('id')
->Pluck('id');
}
}
else {
$this->selected =[];
}
}
public function updatedselected()
{
$this->selectAll = false;
}
<?php
namespace App\Exports;
use App\Models\Charge;
use Maatwebsite\Excel\Facades\Excel;
Use App\Exports\ChargesExport;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
class ChargesExport implements FromCollection, WithMapping, WithHeadings
{
private $chargeids;
public function __construct($chargeids){
$this->chargeids=$chargeids;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return charge::whereIn('id',$this->chargeids) ->selectRaw('*, taskscharges - payment as balance')
->get();
}
// here you select the row that you want in the file
public function map($charge): array
{
return [
$charge->customer->name,
$charge->created_at,
$charge->tasks,
$charge->taskscharges,
$charge->payment,
$charge->balance,
$charge->comments,
$charge->user->name
];
} public function headings(): array
{
return ['Όνομα','Date', 'Εργασίες', 'Χρέωση', 'Πληρωμή', 'Υπόλοιπο', 'Σχόλια', 'Χρήστης'];
}
}
also when i dd the $this->selected i can see that i get all the entries, but still not exporting on excel document.
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.12",
"laravel/jetstream": "^2.3",
"laravel/sanctum": "^2.6",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.0",
"maatwebsite/excel": "^3.1"
},
Please or to participate in this conversation.