sfneal /
models
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Sfneal\Models\Traits; |
||||
| 4 | |||||
| 5 | use Illuminate\Database\Eloquent\Builder; |
||||
| 6 | |||||
| 7 | trait HasCompositePrimaryKey |
||||
| 8 | { |
||||
| 9 | /** |
||||
| 10 | * Get the value indicating whether the IDs are incrementing. |
||||
| 11 | * |
||||
| 12 | * @return bool |
||||
| 13 | */ |
||||
| 14 | public function getIncrementing(): bool |
||||
| 15 | { |
||||
| 16 | return false; |
||||
| 17 | } |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * Set the keys for a save update query. |
||||
| 21 | * |
||||
| 22 | * @param Builder $query |
||||
| 23 | * @return Builder |
||||
| 24 | */ |
||||
| 25 | protected function setKeysForSaveQuery($query): Builder |
||||
| 26 | { |
||||
| 27 | $keys = $this->getKeyName(); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 28 | if (! is_array($keys)) { |
||||
| 29 | return parent::setKeysForSaveQuery($query); |
||||
| 30 | } |
||||
| 31 | |||||
| 32 | foreach ($keys as $keyName) { |
||||
| 33 | $query->where($keyName, '=', $this->getKeyForSaveQuery($keyName)); |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | return $query; |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * Get the primary key value for a save query. |
||||
| 41 | * |
||||
| 42 | * @param string|null $keyName |
||||
| 43 | * @return mixed |
||||
| 44 | */ |
||||
| 45 | protected function getKeyForSaveQuery(string $keyName = null): mixed |
||||
| 46 | { |
||||
| 47 | if (is_null($keyName)) { |
||||
| 48 | $keyName = $this->getKeyName(); |
||||
| 49 | } |
||||
| 50 | |||||
| 51 | if (isset($this->original[$keyName])) { |
||||
| 52 | return $this->original[$keyName]; |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | return $this->getAttribute($keyName); |
||||
|
0 ignored issues
–
show
It seems like
getAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 56 | } |
||||
| 57 | } |
||||
| 58 |