Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117881068
PackageSkuObserver.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
PackageSkuObserver.php
View Options
<?php
namespace
App\Observers
;
use
App\PackageSku
;
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
*
* @param \App\PackageSku $packageSku The package-sku relation
*
* @return void
*/
public
function
created
(
PackageSku
$packageSku
)
{
// TODO: free units...
$package
=
$packageSku
->
package
;
$sku
=
$packageSku
->
sku
;
$package
->
skus
()->
updateExistingPivot
(
$sku
,
[
'cost'
=>
(
$sku
->
cost
*
(
100
-
$package
->
discount_rate
))
/
100
],
false
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Apr 5, 11:39 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18800379
Default Alt Text
PackageSkuObserver.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline