Passed
Push — master ( c2d3c3...2d4925 )
by Innocent
06:21
created

SubscriptionService::getUnsetFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Faithgen\Miscellaneous\Services;
4
5
use Faithgen\Miscellaneous\Models\Subscription;
6
use Illuminate\Database\Eloquent\Model as ParentModel;
7
use InnoFlash\LaraStart\Services\CRUDServices;
8
9
class SubscriptionService extends CRUDServices
10
{
11
    private Subscription $subscription;
12
13
    public function __construct(Subscription $subscription)
14
    {
15
        if (request()->has('subscription_id')) {
16
            $this->subscription = Subscription::findOrFail(request('subscription_id'));
17
        } else {
18
            $this->subscription = $subscription;
19
        }
20
    }
21
22
    /**
23
     * Retrieves an instance of subscription.
24
     */
25
    public function getSubscription(): Subscription
26
    {
27
        return $this->subscription;
28
    }
29
30
    /**
31
     * Makes a list of fields that you do not want to be sent
32
     * to the create or update methods.
33
     * Its mainly the fields that you do not have in the subscriptions table.
34
     */
35
    public function getUnsetFields()
36
    {
37
        return ['subscription_id'];
38
    }
39
40
    /**
41
     * This returns the model found in the constructor
42
     * or an instance of the class if no subscription is found.
43
     */
44
    public function getModel()
45
    {
46
        return $this->getSubscription();
47
    }
48
49
    /**
50
     * Attaches a parent to the current subscription.
51
     * You can delete this if you do not intent to create subscriptions from parent relationships.
52
     */
53
    public function getParentRelationship()
54
    {
55
        return [
56
            ParentModel::class,
57
            'relationshipName',
58
        ];
59
    }
60
}
61