Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/PackageSkuObserver.php
<?php | <?php | ||||
namespace App\Observers; | namespace App\Observers; | ||||
use App\PackageSku; | use App\PackageSku; | ||||
class PackageSkuObserver | class PackageSkuObserver | ||||
{ | { | ||||
/** | /** | ||||
* Handle the "creating" event on an PackageSku relation. | |||||
* | |||||
* Ensures that the entries belong to the same tenant. | |||||
* | |||||
* @param \App\PackageSku $packageSku The package-sku relation | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function creating(PackageSku $packageSku) | |||||
{ | |||||
$package = $packageSku->package; | |||||
$sku = $packageSku->sku; | |||||
if ($package->tenant_id != $sku->tenant_id) { | |||||
throw new \Exception("Package and SKU owned by different tenants"); | |||||
} | |||||
} | |||||
/** | |||||
* Handle the "created" event on an PackageSku relation | * Handle the "created" event on an PackageSku relation | ||||
* | * | ||||
* @param \App\PackageSku $packageSku The package-sku relation | * @param \App\PackageSku $packageSku The package-sku relation | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function created(PackageSku $packageSku) | public function created(PackageSku $packageSku) | ||||
{ | { | ||||
Show All 11 Lines |