mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-07 10:01:47 -04:00
Create hasPublicId property on models and use it to determine whether to set a public id
This commit is contained in:
parent
76af2f3e13
commit
a29929846f
@ -12,6 +12,11 @@ class AccountGatewaySettings extends EntityModel
|
|||||||
*/
|
*/
|
||||||
protected $dates = ['updated_at'];
|
protected $dates = ['updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected static $hasPublicId = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
*/
|
*/
|
||||||
|
@ -15,6 +15,12 @@ class EntityModel extends Eloquent
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected static $hasPublicId = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -58,7 +64,7 @@ class EntityModel extends Eloquent
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
if (static::$hasPublicId) {
|
||||||
$lastEntity = $lastEntity->orderBy('public_id', 'DESC')
|
$lastEntity = $lastEntity->orderBy('public_id', 'DESC')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@ -67,13 +73,6 @@ class EntityModel extends Eloquent
|
|||||||
} else {
|
} else {
|
||||||
$entity->public_id = 1;
|
$entity->public_id = 1;
|
||||||
}
|
}
|
||||||
} catch
|
|
||||||
(QueryException $ex) {
|
|
||||||
// Code 42S22 is for an unknown column.
|
|
||||||
// If we get that code, we'll just swallow the error, since apparently this entity doesn't support public_ids.
|
|
||||||
if ($ex->getCode() !== '42S22') {
|
|
||||||
throw $ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user