Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
25.00% |
1 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| BrandStat | |
25.00% |
1 / 4 |
|
0.00% |
0 / 2 |
6.80 | |
0.00% |
0 / 1 |
| booted | |
33.33% |
1 / 3 |
|
0.00% |
0 / 1 |
3.19 | |||
| brand | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Model; |
| 6 | use Illuminate\Support\Carbon; |
| 7 | |
| 8 | class BrandStat extends Model |
| 9 | { |
| 10 | /** |
| 11 | * Indicates if the model should be timestamped. |
| 12 | * |
| 13 | * @var boolean |
| 14 | */ |
| 15 | public $timestamps = false; |
| 16 | |
| 17 | /** |
| 18 | * The attributes that should be cast to native types. |
| 19 | * |
| 20 | * @var array |
| 21 | */ |
| 22 | public $casts = [ |
| 23 | 'created_at' => 'date' |
| 24 | ]; |
| 25 | |
| 26 | /** |
| 27 | * The attributes that are mass assignable. |
| 28 | * |
| 29 | * @var string[] |
| 30 | */ |
| 31 | protected $fillable = [ |
| 32 | 'active', 'inactive', |
| 33 | 'old_accounts', 'new_accounts', |
| 34 | 'total_accounts', 'total_opt_in' |
| 35 | ]; |
| 36 | |
| 37 | /** |
| 38 | * Perform any actions required after the model boots. |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | protected static function booted() |
| 43 | { |
| 44 | static::creating(function (BrandStat $stat) { |
| 45 | if (!$stat->created_at) { |
| 46 | $stat->created_at = Carbon::now(); |
| 47 | } |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | // * RELATIONS |
| 52 | |
| 53 | /** |
| 54 | * Brand hasMany relation |
| 55 | * |
| 56 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 57 | */ |
| 58 | public function brand() |
| 59 | { |
| 60 | return $this->belongsTo(Brand::class); |
| 61 | } |
| 62 | } |