Page MenuHomePhorge

Entitlement.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

Entitlement.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
The eloquent definition of an entitlement.
Owned by a {@link \App\User}, billed to a {@link \App\Wallet}.
*/
class Entitlement extends Model
{
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'sku_id',
'owner_id',
'user_id',
'wallet_id',
'description'
];
/**
Provide a custom ID (uuid) property.
@return void
*/
protected static function boot()
{
parent::boot();
static::creating(
function ($entitlement) {
$entitlement->{$entitlement->getKeyName()} = \App\Utils::uuidStr();
// Make sure the owner is at least a controller on the wallet
$owner = \App\User::find($entitlement->owner_id);
$wallet = \App\Wallet::find($entitlement->wallet_id);
if (!$owner) {
return false;
}
if (!$wallet) {
return false;
}
if (!$wallet->owner() == $owner) {
if (!$wallet->controllers->contains($owner)) {
return false;
}
}
$sku = \App\Sku::find($entitlement->sku_id);
if (!$sku) {
return false;
}
$wallet->debit($sku->cost);
}
);
}
/**
The SKU concerned.
@return Sku
*/
public function sku()
{
return $this->belongsTo('App\Sku');
}
/**
The owner of this entitlement.
@return User
*/
public function owner()
{
return $this->belongsTo('App\User', 'owner_id');
}
/**
The target user for this entitlement
@return User
*/
public function user()
{
return $this->belongsTo('App\User');
}
/**
The wallet this entitlement is being billed to
@return Wallet
*/
public function wallet()
{
return $this->belongsTo('App\Wallet');
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:49 AM (5 d, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18734559
Default Alt Text
Entitlement.php (2 KB)

Event Timeline