1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models\enso\activitylogs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
use LaravelEnso\TrackWho\Traits\CreatedBy; |
8
|
|
|
|
9
|
|
|
class ActivityLog extends Model |
10
|
|
|
{ |
11
|
|
|
use CreatedBy; |
12
|
|
|
|
13
|
|
|
protected $guarded = ['id']; |
14
|
|
|
|
15
|
|
|
protected $casts = ['meta' => 'object']; |
16
|
|
|
|
17
|
|
|
public function scopeBetween($query, $startDate, $endDate) |
18
|
|
|
{ |
19
|
|
|
$query->when($startDate, fn ($query) => $query |
20
|
|
|
->where('created_at', '>=', Carbon::parse($startDate)))->when($endDate, fn ($query) => $query |
21
|
|
|
->where('created_at', '<', Carbon::parse($endDate))); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function scopeForUsers($query, array $userIds) |
25
|
|
|
{ |
26
|
|
|
$query->when(count($userIds) > 0, fn ($query) => $query |
27
|
|
|
->whereIn('created_by', $userIds)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function scopeForEvents($query, array $events) |
31
|
|
|
{ |
32
|
|
|
$query->when(count($events) > 0, fn ($query) => $query |
33
|
|
|
->whereIn('event', $events)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function scopeForRoles($query, array $roleIds) |
37
|
|
|
{ |
38
|
|
|
$query->when(count($roleIds) > 0, fn ($query) => $query |
39
|
|
|
->whereHas('createdBy', fn ($query) => $query |
40
|
|
|
->whereIn('role_id', $roleIds))); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|