ActivityLinkPivot.php
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace App\Models\Pivots;
use App\Models\Activity;
use App\Models\User;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
* @method static Builder manager(int $userId)
*/
class ActivityLinkPivot extends MorphPivot
{
use Filterable;
protected $table = 'activity_links';
protected $hidden = ['link_type'];
protected $casts = ['expand' => 'json'];
public $timestamps = false;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function activity(): BelongsTo
{
return $this->belongsTo(Activity::class)->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function link(): MorphTo
{
return $this->morphTo()->withTrashed();
}
/**
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param int $userId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeManager(Builder $builder, int $userId): Builder
{
return $builder->where('type', 'manager')->where('link_type', User::class)->where('link_id', $userId);
}
}