Soft delete/restore tokens in sync with CompanyGateway"

This commit is contained in:
David Bomba 2021-01-27 09:17:27 +11:00
parent 70cb7db12f
commit 458dd1fa4a
2 changed files with 10 additions and 2 deletions

View File

@ -87,6 +87,11 @@ class CompanyGateway extends BaseModel
return $this->belongsTo(Company::class);
}
public function client_gateway_tokens()
{
return $this->hasMany(ClientGatewayToken::class);
}
public function gateway()
{
return $this->belongsTo(Gateway::class, 'gateway_key', 'key');

View File

@ -2,6 +2,7 @@
namespace App\Observers;
use App\Models\ClientGatewayToken;
use App\Models\CompanyGateway;
class CompanyGatewayObserver
@ -41,7 +42,8 @@ class CompanyGatewayObserver
*/
public function deleted(CompanyGateway $company_gateway)
{
//
//when we soft delete a gateway - we also soft delete the tokens
$company_gateway->client_gateway_tokens()->delete();
}
/**
@ -52,7 +54,8 @@ class CompanyGatewayObserver
*/
public function restored(CompanyGateway $company_gateway)
{
//
//When we restore the gateway, bring back the tokens!
ClientGatewayToken::where('company_gateway_id', $company_gateway->id)->withTrashed()->get()->restore();
}
/**