ShowReports.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 $title = "Test Report";
  16. public function mount($reportName)
  17. {
  18. // Receive the dynamic datatable name during initialization
  19. $this->reportName = $reportName;
  20. // Fetch the DataTable configuration
  21. $datatableConfigQuery = DB::table('reports')->where('name', $reportName)->first();
  22. if (!$datatableConfigQuery) {
  23. abort(404, 'DataTable configuration not found');
  24. }
  25. // Store the decoded JSON as a plain array
  26. $this->datatableColumnsConfig = json_decode($datatableConfigQuery->columns_config, true);
  27. $this->datatableHeadersConfig = json_decode($datatableConfigQuery->column_headers, true);
  28. $this->datatableColumnDefsConfig = json_decode($datatableConfigQuery->column_defs, true);
  29. $this->datatableButtonsConfig = json_decode($datatableConfigQuery->buttons, true);
  30. }
  31. public function render()
  32. {
  33. return view('livewire.show-reports')->title($this->title)->layout('components.layouts.reports');
  34. }
  35. }