DictionaryCampaign.php
1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace App\Models\Pivots;
use App\Models\Campaigns;
use App\Models\Dictionary;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* App\Models\Pivots\DictionaryCampaign
*
* @property-read Campaigns $campaign
* @property-read Dictionary $dictionary
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign query()
* @mixin \Eloquent
*/
class DictionaryCampaign extends Pivot
{
protected $fillable = [
'campaign_id',
'dictionary_id',
'name',
'negative_keywords',
'excluded_sites',
'updated',
];
protected $cast = [
'campaign_id' => 'int',
'dictionary_id' => 'int',
'updated' => 'boolean',
];
static public function getWithPivot()
{
return [
'name',
'negative_keywords',
'excluded_sites',
'updated',
];
}
static public function copyPropertyInCampaign(Campaigns $campaign)
{
return collect(self::getWithPivot())
->filter(function ($property_name){
return $property_name !== 'updated';
})
->transform(function ($property_name) use ($campaign) {
return [
$property_name => $campaign->{$property_name}
];
})->flatMap(function ($val){
return $val;
})->all();
}
public function dictionary()
{
return $this->belongsTo(Dictionary::class, 'dictionary_id');
}
public function campaign()
{
return $this->belongsTo(Campaigns::class, 'campaign_id');
}
}