1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Observers/CompanyGatewayObserver.php
Shift 19080933b6
Apply Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started.

For more information on customizing the code style applied by Shift, [watch this short video][4].

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://github.com/squizlabs/PHP_CodeSniffer
[3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
[4]: https://laravelshift.com/videos/shift-code-style
2022-06-21 09:57:17 +00:00

75 lines
1.8 KiB
PHP

<?php
namespace App\Observers;
use App\Models\ClientGatewayToken;
use App\Models\CompanyGateway;
class CompanyGatewayObserver
{
/**
* Handle the company gateway "created" event.
*
* @param CompanyGateway $company_gateway
* @return void
*/
public function created(CompanyGateway $company_gateway)
{
/* Set company gateway if not exists*/
if (! $company_gateway->label) {
$company_gateway->label = $company_gateway->gateway->name;
$company_gateway->save();
}
}
/**
* Handle the company gateway "updated" event.
*
* @param CompanyGateway $company_gateway
* @return void
*/
public function updated(CompanyGateway $company_gateway)
{
//
}
/**
* Handle the company gateway "deleted" event.
*
* @param CompanyGateway $company_gateway
* @return void
*/
public function deleted(CompanyGateway $company_gateway)
{
//when we soft delete a gateway - we also soft delete the tokens
$company_gateway->client_gateway_tokens()->delete();
}
/**
* Handle the company gateway "restored" event.
*
* @param CompanyGateway $company_gateway
* @return void
*/
public function restored(CompanyGateway $company_gateway)
{
//When we restore the gateway, bring back the tokens!
ClientGatewayToken::where('company_gateway_id', $company_gateway->id)
->withTrashed()->cursor()->each(function ($cgt) {
$cgt->restore();
});
}
/**
* Handle the company gateway "force deleted" event.
*
* @param CompanyGateway $company_gateway
* @return void
*/
public function forceDeleted(CompanyGateway $company_gateway)
{
//
}
}