-
Notifications
You must be signed in to change notification settings - Fork 24
/
Licensable.php
41 lines (35 loc) · 979 Bytes
/
Licensable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace LaravelReady\LicenseServer\Traits;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use LaravelReady\LicenseServer\Models\LicensableProduct;
trait Licensable
{
/**
* Licensable product relationship
*/
public function licensable(): MorphOne
{
return $this->morphOne(LicensableProduct::class, 'licensable')
->select('id', 'licensable_id', 'licensable_type', 'license_id', 'user_id')
->with([
'license' => fn ($query) => $query->first(),
]);
}
/**
* Licensable product item relationship
*/
public function licensed(): HasOne
{
return $this->hasOne(LicensableProduct::class);
}
/**
* Licensed to product relationship
*/
public function licensedTo(): HasOne
{
return $this->hasOne(LicensableProduct::class)->with([
'product'
]);
}
}