123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class NewMediaCount extends Model
- {
- //
- protected $table = 'new_media_count';
- protected $fillable = ['day','year','month'];
- protected $appends = ['month','year', 'count_data'];
- protected $casts = [
- 'count_data' => 'array',
- ];
- // protected $guarded = ['year','month'];
- protected static function booting()
- {
- static::creating(function ($model) {
- $model->day = $model->year . '-' . $model->month ;
- unset($model->year, $model->month);
- });
- }
- protected function getMonthAttribute()
- {
- return date('m', strtotime($this->day));
- }
- protected function getYearAttribute()
- {
- return date('Y', strtotime($this->day));
- }
- protected function getCountDataAttribute()
- {
- return @NewMediaCountRecord::where('nmc_id', $this->id)->get()->toArray();
- }
- }
|