Step::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Infinitypaul\MultiStep\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Infinitypaul\MultiStep\Controller\Keys;
7
8
class Step extends Model
9
{
10
    protected $guarded = ['id'];
11
12
    protected $casts = [
13
        'data' => 'array',
14
    ];
15
16
    public function __construct(array $attributes = [])
17
    {
18
        parent::__construct($attributes);
19
        $this->setTable(config('steps.table_names'));
20
    }
21
22
    protected static function booted()
23
    {
24
        static::creating(function ($step) {
25
            self::getHashedKeys();
26
            $step->slug = session()->get('step_key');
27
        });
28
    }
29
30
    protected static function getHashedKeys()
31
    {
32
        $key = Keys::getHashedToken();
33
        while (self::where('slug', $key)->exists()) {
34
            $key = Keys::getHashedToken();
35
        }
36
        session(['step_key' => $key]);
37
    }
38
}
39