Completed
Push — master ( a6516d...da5039 )
by Scott
224:29 queued 164:15
created

Cart::scopeIsOpen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Bedard\Shop\Models;
2
3
use Model;
4
5
/**
6
 * Cart Model.
7
 */
8
class Cart extends Model
9
{
10
    /**
11
     * @var string The database table used by the model.
12
     */
13
    public $table = 'bedard_shop_carts';
14
15
    /**
16
     * @var array Guarded fields
17
     */
18
    protected $guarded = ['*'];
19
20
    /**
21
     * @var array Fillable fields
22
     */
23
    protected $fillable = [
24
        'token',
25
    ];
26
27
    /**
28
     * @var array Relations
29
     */
30
    public $hasMany = [
31
        'items' => [
32
            'Bedard\Shop\Models\CartItem',
33
        ],
34
    ];
35
36
    /**
37
     * Before create.
38
     *
39
     * @return void
40
     */
41
    public function beforeCreate()
42
    {
43
        $this->generateToken();
44
    }
45
46
    /**
47
     * Generate a unique token.
48
     *
49
     * @return void
50
     */
51
    protected function generateToken()
52
    {
53
        do {
54
            $this->token = str_random(40);
55
        } while (self::whereToken($this->token)->exists());
56
    }
57
58
    /**
59
     * Select carts that are open.
60
     *
61
     * @param  \October\Rain\Database\Builder   $query
62
     * @return \October\Rain\Database\Builder
63
     */
64
    public function scopeIsOpen($query)
65
    {
66
        return $query; // @todo
67
    }
68
}
69