ShowReports.php 1.1 KB

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