| @@ 9-36 (lines=28) @@ | ||
| 6 | use Illuminate\Database\Eloquent\Model; |
|
| 7 | use Ben182\AbTesting\Events\ExperimentNewVisitor; |
|
| 8 | ||
| 9 | class Experiment extends Model |
|
| 10 | { |
|
| 11 | protected $table = 'ab_experiments'; |
|
| 12 | ||
| 13 | protected $fillable = [ |
|
| 14 | 'name', |
|
| 15 | 'visitors', |
|
| 16 | ]; |
|
| 17 | ||
| 18 | protected $casts = [ |
|
| 19 | 'visitors' => 'integer', |
|
| 20 | ]; |
|
| 21 | ||
| 22 | public function goals() |
|
| 23 | { |
|
| 24 | return $this->hasMany(Goal::class); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function visit() |
|
| 28 | { |
|
| 29 | if (AbTestingFacade::isCrawler()) { |
|
| 30 | return; |
|
| 31 | } |
|
| 32 | ||
| 33 | $this->increment('visitors'); |
|
| 34 | event(new ExperimentNewVisitor($this)); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| @@ 9-36 (lines=28) @@ | ||
| 6 | use Illuminate\Database\Eloquent\Model; |
|
| 7 | use Ben182\AbTesting\Events\GoalCompleted; |
|
| 8 | ||
| 9 | class Goal extends Model |
|
| 10 | { |
|
| 11 | protected $table = 'ab_goals'; |
|
| 12 | ||
| 13 | protected $fillable = [ |
|
| 14 | 'name', |
|
| 15 | 'hit', |
|
| 16 | ]; |
|
| 17 | ||
| 18 | protected $casts = [ |
|
| 19 | 'hit' => 'integer', |
|
| 20 | ]; |
|
| 21 | ||
| 22 | public function experiment() |
|
| 23 | { |
|
| 24 | return $this->belongsTo(Experiment::class); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function complete() |
|
| 28 | { |
|
| 29 | if (AbTestingFacade::isCrawler()) { |
|
| 30 | return; |
|
| 31 | } |
|
| 32 | ||
| 33 | $this->increment('hit'); |
|
| 34 | event(new GoalCompleted($this)); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||