ShowReports.php 1.3 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 $datatableName;
  11. public $datatableColumnsConfig;
  12. public $datatableHeadersConfig;
  13. public array $searchTerms = [];
  14. public function mount($datatableName)
  15. {
  16. // Receive the dynamic datatable name during initialization
  17. $this->datatableName = $datatableName;
  18. // Fetch the DataTable configuration
  19. $datatableConfigQuery = DB::table('datatables')->where('name', $datatableName)->first();
  20. if (!$datatableConfigQuery) {
  21. abort(404, 'DataTable configuration not found');
  22. }
  23. // Store the decoded JSON as a plain array
  24. $this->datatableColumnsConfig = json_decode($datatableConfigQuery->columns_config, true);
  25. $this->datatableHeadersConfig = json_decode($datatableConfigQuery->column_headers, true);
  26. }
  27. public function updatedSearchTerms($value)
  28. {
  29. $this->dispatch('search-terms-updated', $this->searchTerms);
  30. }
  31. public function render()
  32. {
  33. return view('livewire.show-reports')->layout('components.layouts.datatables');
  34. }
  35. }