|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gitamin\Models; |
|
13
|
|
|
|
|
14
|
|
|
use AltThree\Validator\ValidatingTrait; |
|
15
|
|
|
use Gitamin\Presenters\SubscriberPresenter; |
|
16
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
17
|
|
|
use McCool\LaravelAutoPresenter\HasPresenter; |
|
18
|
|
|
|
|
19
|
|
|
class Subscriber extends Model implements HasPresenter |
|
20
|
|
|
{ |
|
21
|
|
|
use ValidatingTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes that should be casted to native types. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string[] |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $casts = [ |
|
29
|
|
|
'id' => 'int', |
|
30
|
|
|
'email' => 'string', |
|
31
|
|
|
'verify_code' => 'string', |
|
32
|
|
|
'verified_at' => 'date', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The fillable properties. |
|
37
|
|
|
* |
|
38
|
|
|
* @var string[] |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $fillable = ['email']; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The validation rules. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string[] |
|
46
|
|
|
*/ |
|
47
|
|
|
public $rules = [ |
|
48
|
|
|
'email' => 'required|email', |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Overrides the models boot method. |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function boot() |
|
55
|
|
|
{ |
|
56
|
|
|
parent::boot(); |
|
57
|
|
|
|
|
58
|
|
|
self::creating(function ($user) { |
|
59
|
|
|
if (! $user->verify_code) { |
|
60
|
|
|
$user->verify_code = self::generateVerifyCode(); |
|
61
|
|
|
} |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Determines if the subscriber is verified. |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function verified() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->verified_at !== null; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns an new verify code. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function generateVerifyCode() |
|
81
|
|
|
{ |
|
82
|
|
|
return str_random(42); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get the presenter class. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getPresenterClass() |
|
91
|
|
|
{ |
|
92
|
|
|
return SubscriberPresenter::class; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.