Seoable::seo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\LaravelSeo\Traits;
2
3
use Arcanedev\LaravelSeo\Models\Meta;
4
5
/**
6
 * Trait     Seoable
7
 *
8
 * @package  Arcanedev\LaravelSeo\Traits
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  \Arcanedev\LaravelSeo\Models\Meta  seo
12
 *
13
 * @method  \Illuminate\Database\Eloquent\Relations\MorphOne  morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
14
 */
15
trait Seoable
16
{
17
    /* -----------------------------------------------------------------
18
     |  Relationships
19
     | -----------------------------------------------------------------
20
     */
21
22
    /**
23
     * SEO relationship.
24
     *
25
     * @return \Illuminate\Database\Eloquent\Relations\MorphOne
26
     */
27 20
    public function seo()
28
    {
29 20
        return $this->morphOne(Meta::class, 'seoable');
30
    }
31
32
    /* -----------------------------------------------------------------
33
     |  Main Methods
34
     | -----------------------------------------------------------------
35
     */
36
37
    /**
38
     * Create a SEO Meta.
39
     *
40
     * @param  array  $attributes
41
     *
42
     * @return \Arcanedev\LaravelSeo\Models\Meta|mixed
43
     */
44 20
    public function createSeo(array $attributes)
45
    {
46 20
        return $this->seo()->create(
47 20
            Meta::prepareAttributes($attributes)
48
        );
49
    }
50
51
    /**
52
     * Update a SEO Meta.
53
     *
54
     * @param  array  $attributes
55
     *
56
     * @return bool
57
     */
58 4
    public function updateSeo(array $attributes)
59
    {
60 4
        return $this->seo->update($attributes);
61
    }
62
63
    /**
64
     * Delete a seo.
65
     *
66
     * @return bool|null
67
     */
68 4
    public function deleteSeo()
69
    {
70 4
        return $this->seo->delete();
71
    }
72
73
    /**
74
     * Check if it has seo.
75
     *
76
     * @return bool
77
     */
78 20
    public function hasSeo()
79
    {
80 20
        return ! is_null($this->seo);
81
    }
82
}
83