From cf95b2dab4018a50777b0f9578b3b51c0349b30f Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 12 Nov 2024 21:03:47 +1100 Subject: [PATCH] Deprecate singleOrNew(), we use firstOrNew() instead --- app/Classes/FTN/Packet.php | 2 +- app/Models/Address.php | 4 ++-- app/Traits/Single.php | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 8e24d25..eea9254 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -263,7 +263,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable case 'software': Software::unguard(); - $o = Software::singleOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]); + $o = Software::firstOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]); Software::reguard(); return $o; diff --git a/app/Models/Address.php b/app/Models/Address.php index eb7e9f0..8981c24 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -120,7 +120,7 @@ class Address extends Model // Check Domain exists Domain::unguard(); - $do = Domain::singleOrNew(['name'=>$ftn['d']]); + $do = Domain::firstOrNew(['name'=>$ftn['d']]); Domain::reguard(); if (! $do->exists) { @@ -143,7 +143,7 @@ class Address extends Model // Create zone Zone::unguard(); - $zo = Zone::singleOrNew(['domain_id'=>$do->id,'zone_id'=>$ftn['z']]); + $zo = Zone::firstOrNew(['domain_id'=>$do->id,'zone_id'=>$ftn['z']]); Zone::reguard(); if (! $zo->exists) { diff --git a/app/Traits/Single.php b/app/Traits/Single.php index 22d251a..e7b2bed 100644 --- a/app/Traits/Single.php +++ b/app/Traits/Single.php @@ -21,15 +21,5 @@ trait Single return NULL; }); - - // When a query should return 1 object, or NULL if it doesnt - Builder::macro('singleOrNew',function ($args) { - $result = $this->where($args)->get(); - - if ($result->count() === 1) - return $result->first(); - - return $this->newModelInstance($args); - }); } } \ No newline at end of file