From 42ff4828866fa4133b3ca522876067ec059b35d0 Mon Sep 17 00:00:00 2001 From: mahdihty Date: Sat, 6 Mar 2021 16:22:03 +0330 Subject: [PATCH] add model --- app/Models/Activity.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 805e4a8..ed20699 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -2,8 +2,37 @@ namespace App\Models; -use App\Models\Model; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; + class Activity extends Model { + use HasFactory; + + protected $fillable = [ + 'business_id', 'project_id', 'system_id', 'workflow_id', 'status_id', 'sprint_id', + 'actor_id', 'task_id', 'subject_id', 'user_id', 'crud_id', 'table_id', 'original', 'diff' + ]; + + public $casts = [ + 'original' => 'array', + 'diff' => 'array', + ]; + + public function scopeCreatesBefore($query, $date) + { + return $query->whereDate('created_at', '<=', Carbon::parse($date)); + } + public function scopeCreatesAfter($query, $date) + { + return $query->whereDate('created_at', '>=', Carbon::parse($date)); + } + public function scopeCreatesIn($query, $days) + { + return $days != "" ? + $query->whereDate('created_at', '>=', Carbon::now()->modify('-'.$days.' day')->toDate()) : + $query; + } }