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; + } }