1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/laravel-follow |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overtrue\LaravelFollow; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany as BaseBelongsToMany; |
15
|
|
|
|
16
|
|
|
class BelongsToMany extends BaseBelongsToMany |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Attach a model to the parent. |
20
|
|
|
* |
21
|
|
|
* @param mixed $id |
22
|
|
|
* @param array $attributes |
23
|
|
|
* @param bool $touch |
24
|
|
|
*/ |
25
|
|
|
public function attach($id, array $attributes = [], $touch = true) |
26
|
|
|
{ |
27
|
|
|
$this->parent->setPivotChanges('attach', $this->getRelationName(), [ |
28
|
|
|
$id => $attributes, |
29
|
|
|
]); |
30
|
|
|
|
31
|
|
|
if (false === $this->parent->firePivotAttachingEvent()) { |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$result = parent::attach($id, $attributes, $touch); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$this->parent->firePivotAttachedEvent(); |
38
|
|
|
|
39
|
|
|
return $result; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Detach models from the relationship. |
44
|
|
|
* |
45
|
|
|
* @param mixed $ids |
46
|
|
|
* @param bool $touch |
47
|
|
|
* |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
|
|
public function detach($ids = null, $touch = true) |
51
|
|
|
{ |
52
|
|
|
if (is_null($ids)) { |
53
|
|
|
$ids = $this->query->pluck( |
54
|
|
|
$this->query->qualifyColumn($this->relatedKey) |
55
|
|
|
)->toArray(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$idsWithAttributes = collect($ids)->mapWithKeys(function ($id) { |
59
|
|
|
return [$id => []]; |
60
|
|
|
})->all(); |
61
|
|
|
|
62
|
|
|
$this->parent->setPivotChanges('detach', $this->getRelationName(), $idsWithAttributes); |
63
|
|
|
|
64
|
|
|
if (false === $this->parent->firePivotDetachingEvent()) { |
65
|
|
|
return false; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$result = parent::detach($ids, $touch); |
69
|
|
|
|
70
|
|
|
$this->parent->firePivotDetachedEvent(); |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Update an existing pivot record on the table. |
77
|
|
|
* |
78
|
|
|
* @param mixed $id |
79
|
|
|
* @param array $attributes |
80
|
|
|
* @param bool $touch |
81
|
|
|
* |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
|
|
public function updateExistingPivot($id, array $attributes, $touch = true) |
85
|
|
|
{ |
86
|
|
|
$this->parent->setPivotChanges('update', $this->getRelationName(), [ |
87
|
|
|
$id => $attributes, |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
if (false === $this->parent->firePivotUpdatingEvent()) { |
91
|
|
|
return false; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$result = parent::updateExistingPivot($id, $attributes, $touch); |
95
|
|
|
|
96
|
|
|
$this->parent->firePivotUpdatedEvent(); |
97
|
|
|
|
98
|
|
|
return $result; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.