/ app / Traits / ComponentHasModels.php
ComponentHasModels.php
 1  <?php
 2  
 3  namespace App\Traits;
 4  
 5  trait ComponentHasModels
 6  {
 7      protected $hasWireModel;
 8  
 9      protected $hasXModel;
10  
11      public function hasBoundModel(): bool
12      {
13          return $this->hasWireModel() || $this->hasXModel();
14      }
15  
16      public function hasWireModel(): bool
17      {
18          if ($this->hasWireModel !== null) {
19              return $this->hasWireModel;
20          }
21  
22          return $this->hasWireModel = $this->attributes->hasStartsWith('wire:model');
23      }
24  
25      public function hasXModel(): bool
26      {
27          if ($this->hasXModel !== null) {
28              return $this->hasXModel;
29          }
30  
31          return $this->hasXModel = $this->attributes->hasStartsWith('x-model');
32      }
33  }