Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117755392
EntitleableTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
995 B
Referenced Files
None
Subscribers
None
EntitleableTrait.php
View Options
<?php
namespace
App\Traits
;
trait
EntitleableTrait
{
/**
* Entitlements for this object.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public
function
entitlements
()
{
return
$this
->
hasMany
(
\App\Entitlement
::
class
,
'entitleable_id'
,
'id'
)
->
where
(
'entitleable_type'
,
self
::
class
);
}
/**
* Returns the wallet by which the object is controlled
*
* @return ?\App\Wallet A wallet object
*/
public
function
wallet
():
?
\App\Wallet
{
$entitlement
=
$this
->
entitlements
()->
withTrashed
()->
orderBy
(
'created_at'
,
'desc'
)->
first
();
if
(
$entitlement
)
{
return
$entitlement
->
wallet
;
}
// TODO: No entitlement should not happen, but in tests we have
// such cases, so we fallback to the user's wallet in this case
if
(
$this
instanceof
\App\User
)
{
return
$this
->
wallets
()->
first
();
}
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 8:01 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823115
Default Alt Text
EntitleableTrait.php (995 B)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline