Deprecate singleOrNew(), we use firstOrNew() instead
This commit is contained in:
parent
24144de193
commit
521a9b0679
@ -263,7 +263,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
|||||||
|
|
||||||
case 'software':
|
case 'software':
|
||||||
Software::unguard();
|
Software::unguard();
|
||||||
$o = Software::singleOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]);
|
$o = Software::firstOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]);
|
||||||
Software::reguard();
|
Software::reguard();
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
@ -120,7 +120,7 @@ class Address extends Model
|
|||||||
|
|
||||||
// Check Domain exists
|
// Check Domain exists
|
||||||
Domain::unguard();
|
Domain::unguard();
|
||||||
$do = Domain::singleOrNew(['name'=>$ftn['d']]);
|
$do = Domain::firstOrNew(['name'=>$ftn['d']]);
|
||||||
Domain::reguard();
|
Domain::reguard();
|
||||||
|
|
||||||
if (! $do->exists) {
|
if (! $do->exists) {
|
||||||
@ -143,7 +143,7 @@ class Address extends Model
|
|||||||
|
|
||||||
// Create zone
|
// Create zone
|
||||||
Zone::unguard();
|
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();
|
Zone::reguard();
|
||||||
|
|
||||||
if (! $zo->exists) {
|
if (! $zo->exists) {
|
||||||
|
@ -21,15 +21,5 @@ trait Single
|
|||||||
|
|
||||||
return NULL;
|
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user