2021-10-29 12:53:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
|
|
class BrandStat extends Model
|
|
|
|
|
{
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* Indicates if the model should be timestamped.
|
|
|
|
|
*
|
|
|
|
|
* @var boolean
|
|
|
|
|
*/
|
2021-10-29 12:53:46 +02:00
|
|
|
public $timestamps = false;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2021-10-29 12:53:46 +02:00
|
|
|
public $casts = [
|
|
|
|
|
'created_at' => 'date'
|
|
|
|
|
];
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
2021-10-29 12:53:46 +02:00
|
|
|
protected $fillable = [
|
|
|
|
|
'active', 'inactive',
|
|
|
|
|
'old_accounts', 'new_accounts',
|
|
|
|
|
'total_accounts', 'total_opt_in'
|
|
|
|
|
];
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2021-10-29 12:53:46 +02:00
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(function (BrandStat $stat) {
|
2021-11-03 11:18:19 +01:00
|
|
|
if (!$stat->created_at) {
|
|
|
|
|
$stat->created_at = Carbon::now();
|
|
|
|
|
}
|
2021-10-29 12:53:46 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * RELATIONS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Brand hasMany relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2021-10-29 12:53:46 +02:00
|
|
|
public function brand()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
|
|
|
|
}
|
|
|
|
|
}
|