You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1010 B

4 years ago
4 years ago
  1. <?php
  2. namespace App\Models;
  3. use Carbon\Carbon;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Activity extends Model
  7. {
  8. use HasFactory;
  9. protected $fillable = [
  10. 'business_id', 'project_id', 'system_id', 'workflow_id', 'status_id', 'sprint_id',
  11. 'actor_id', 'task_id', 'subject_id', 'user_id', 'crud_id', 'table_id', 'original', 'diff'
  12. ];
  13. public $casts = [
  14. 'original' => 'array',
  15. 'diff' => 'array',
  16. ];
  17. public function scopeCreatesBefore($query, $date)
  18. {
  19. return $query->whereDate('created_at', '<=', Carbon::parse($date));
  20. }
  21. public function scopeCreatesAfter($query, $date)
  22. {
  23. return $query->whereDate('created_at', '>=', Carbon::parse($date));
  24. }
  25. public function scopeCreatesIn($query, $days)
  26. {
  27. return $days != "" ?
  28. $query->whereDate('created_at', '>=', Carbon::now()->modify('-'.$days.' day')->toDate()) :
  29. $query;
  30. }
  31. }