ShowReports.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Livewire;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Collection;
  5. use Illuminate\Support\Facades\App;
  6. use Illuminate\Support\Facades\DB;
  7. use Livewire\Component;
  8. class ShowReports extends Component
  9. {
  10. public $reportName;
  11. public $datatableColumnsConfig;
  12. public $datatableHeadersConfig;
  13. public $datatableButtonsConfig;
  14. public $datatableColumnDefsConfig;
  15. public function mount($reportName)
  16. {
  17. // Receive the dynamic datatable name during initialization
  18. $this->reportName = $reportName;
  19. // Fetch the DataTable configuration
  20. $datatableConfigQuery = DB::table('reports')->where('name', $reportName)->first();
  21. if (!$datatableConfigQuery) {
  22. abort(404, 'DataTable configuration not found');
  23. }
  24. // Store the decoded JSON as a plain array
  25. $this->datatableColumnsConfig = json_decode($datatableConfigQuery->columns_config, true);
  26. $this->datatableHeadersConfig = json_decode($datatableConfigQuery->column_headers, true);
  27. $this->datatableColumnDefsConfig = json_decode($datatableConfigQuery->column_defs, true);
  28. $this->datatableButtonsConfig = json_decode($datatableConfigQuery->buttons, true);
  29. }
  30. public function render()
  31. {
  32. return view('livewire.show-reports')->layout('components.layouts.reports');
  33. }
  34. }