Index.php
1 <?php 2 3 namespace App\Http\Livewire\CertifiedProducts; 4 5 use App\Http\Services\CertifiedProductsService; 6 use App\Models\Dossier; 7 use App\Models\DossierType; 8 use App\Models\TOE; 9 use App\Traits\WithPerPagePagination; 10 use Illuminate\Foundation\Auth\Access\AuthorizesRequests; 11 use Livewire\Component; 12 use Livewire\WithPagination; 13 14 class Index extends Component 15 { 16 use AuthorizesRequests, WithPagination, WithPerPagePagination; 17 18 public string $search = ''; 19 20 public array $filters = [ 21 'toe' => [], 22 'type' => null, 23 'mode' => null, 24 'subtype' => null, 25 'manufacturer' => [], 26 ]; 27 28 public string $sortField = 'created_at'; 29 public string $sortDirection = 'asc'; 30 31 public bool $readyToLoad = false; 32 33 public function mount() 34 { 35 $this->authorize('can_read_certified_products'); 36 } 37 38 public function fetchData() 39 { 40 $this->readyToLoad = true; 41 } 42 43 public function getRowsQueryProperty() 44 { 45 return CertifiedProductsService::search($this->search, $this->sortField, $this->sortDirection, $this->filters); 46 } 47 48 public function getCertifiedProductsProperty() 49 { 50 return $this->readyToLoad ? $this->applyPagination($this->rowsQuery) : []; 51 } 52 53 public function getTOESProperty() 54 { 55 return TOE::all(['id', 'name'])->toArray(); 56 } 57 58 public function getDossierTypesProperty() 59 { 60 return DossierType::all(['id', 'name'])->toArray(); 61 } 62 63 public function getNormScopes(Dossier $dossier) 64 { 65 return $dossier->norm->normScopes->map(function ($normScope) { 66 return $normScope->name; 67 })->implode(' + '); 68 } 69 70 public function getProtectionProfiles(Dossier $dossier) 71 { 72 return $dossier->protectionProfiles->map(function ($protectionProfile) { 73 return $protectionProfile->name; 74 })->implode('\n'); 75 } 76 77 public function viewRow(int $rowId) 78 { 79 return redirect()->to(route('toes.toe.view', ['toe' => $rowId])); 80 } 81 82 public function render() 83 { 84 return view('livewire.certified-products.index') 85 ->layoutData([ 86 'title' => __('certified-products.title'), 87 'entity' => null, 88 'breadcrumb' => 'certified-products.index', 89 ]); 90 } 91 }