@@ -25,20 +25,20 @@ public function __construct($related, $owner, $name, $field, $updateFields = [])
25
25
$ this ->boot ();
26
26
}
27
27
28
- protected function setUpdateFields ($ fields )
28
+ protected function setUpdateFields ($ fields )
29
29
{
30
30
$ this ->updateFields = $ fields ;
31
31
if ($ this ->owner ->hasKey ()){
32
32
$ this ->updateFields [$ this ->field ] = $ this ->owner ->getKey ();
33
33
}
34
34
}
35
35
36
- public function hasUpdateFields ()
36
+ public function hasUpdateFields ()
37
37
{
38
38
return $ this ->updateFields != [];
39
39
}
40
40
41
- public function getUpdateKeys ()
41
+ public function getUpdateKeys ()
42
42
{
43
43
return array_keys ($ this ->updateFields );
44
44
}
@@ -56,7 +56,7 @@ public function updateFields($item){
56
56
return $ item ;
57
57
}
58
58
59
- public function boot ()
59
+ public function boot ()
60
60
{
61
61
if (array_key_exists ($ this ->name , $ this ->owner ->getAttributes ())){
62
62
$ this ->hydrate ($ this ->owner ->getAttributes ()[$ this ->name ]);
@@ -75,7 +75,7 @@ public function boot()
75
75
}
76
76
}
77
77
78
- protected function hydrate ($ array )
78
+ protected function hydrate ($ array )
79
79
{
80
80
$ collection = new Collection ;
81
81
if ($ array != []){
@@ -86,15 +86,15 @@ protected function hydrate($array)
86
86
$ this ->relation = $ collection ;
87
87
}
88
88
89
- public function empty ()
89
+ public function empty ()
90
90
{
91
91
$ this ->relation = new Collection ;
92
92
return $ this ;
93
93
}
94
94
95
95
public function make ($ data )
96
96
{
97
- $ this ->attach ($ this ->newRelation ($ this ->updateFields ($ data )));
97
+ $ this ->attach (( $ object = $ this ->newRelation ($ this ->updateFields ($ data) )));
98
98
return $ object ;
99
99
}
100
100
@@ -106,7 +106,7 @@ public function attach($object)
106
106
107
107
public function detach ($ object )
108
108
{
109
-
109
+
110
110
}
111
111
112
112
public function save (object $ object )
@@ -140,25 +140,25 @@ public function createMany(array $data)
140
140
return $ this ;
141
141
}
142
142
143
- public function getResults ()
143
+ public function getResults ()
144
144
{
145
145
if ($ this ->relation ->count () == 0 ){
146
146
$ this ->getRelationFromApi ();
147
- }
147
+ }
148
148
return $ this ->relation ;
149
149
}
150
150
151
- public function first ()
151
+ public function first ()
152
152
{
153
153
return $ this ->getResults ()->first ()->fresh ();
154
154
}
155
155
156
- public function last ()
156
+ public function last ()
157
157
{
158
158
return $ this ->getResults ()->last ()->fresh ();
159
159
}
160
160
161
- public function getRelationFromApi ()
161
+ public function getRelationFromApi ()
162
162
{
163
163
$ this ->relation = $ this ->newRelation ($ this ->updateFields ([]))->setPassOnAttributes ($ this ->getUpdateKeys ())->all ();
164
164
if ($ this ->hasUpdateFields ()){
@@ -169,7 +169,7 @@ public function getRelationFromApi()
169
169
return $ this ;
170
170
}
171
171
172
- public function nextPage ()
172
+ public function nextPage ()
173
173
{
174
174
$ this ->relation = $ this ->relation ->nextPage ();
175
175
if ($ this ->hasUpdateFields ()){
@@ -179,7 +179,7 @@ public function nextPage()
179
179
}
180
180
}
181
181
182
- public function prevPage ()
182
+ public function prevPage ()
183
183
{
184
184
$ this ->relation = $ this ->relation ->prevPage ();
185
185
if ($ this ->hasUpdateFields ()){
@@ -203,9 +203,9 @@ public function __call($method, $parameters)
203
203
} else {
204
204
$ relation = $ this ->newRelation ($ this ->updateFields ([]))->setPassOnAttributes ($ this ->getUpdateKeys ());
205
205
return $ this ->forwardCallTo ($ relation , $ method , $ parameters );
206
- }
206
+ }
207
207
}
208
208
209
209
// Be good to add these:- findOrNew, firstOrNew, firstOrCreate and updateOrCreate
210
210
211
- }
211
+ }
0 commit comments