dev-think-one /
nova-page-settings
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Thinkone\NovaPageSettings\QueryAdapter; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Builder as EloquentBuilder; |
||
| 6 | use Illuminate\Database\Eloquent\Model; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @extends \Illuminate\Database\Eloquent\Builder<Model> |
||
| 10 | */ |
||
| 11 | class SettingsQueryBuilder extends EloquentBuilder |
||
| 12 | { |
||
| 13 | |||
| 14 | 2 | public function find($id, $columns = [ '*' ]): mixed |
|
| 15 | { |
||
| 16 | 2 | return $this->get()->firstWhere(InternalSettingsModel::ATTR_ID, $id); |
|
| 17 | } |
||
| 18 | |||
| 19 | 2 | public function first($columns = [ '*' ]): mixed |
|
| 20 | { |
||
| 21 | /* ad-hoc solution to prevent real call to database */ |
||
| 22 | 2 | $wheres = $this->query->wheres; |
|
| 23 | 2 | $key = InternalSettingsModel::ATTR_ID; |
|
| 24 | 2 | $val = collect($wheres)->firstWhere('column', "{$this->query->from}.{$key}"); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | |||
| 26 | 2 | if ($val) { |
|
| 27 | 1 | return $this->find($val['value']); |
|
| 28 | } |
||
| 29 | |||
| 30 | 1 | return parent::first($columns); |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | public function exists(): bool |
|
| 34 | { |
||
| 35 | 1 | return !!$this->first(); |
|
| 36 | } |
||
| 37 | } |
||
| 38 |