@@ -69,7 +69,7 @@ public function __construct(
69
69
*/
70
70
public function hint ()
71
71
{
72
- return '\\' . Collection::class. '| ' . $ this ->reference ->getQualifiedUserClassName (). '[] ' ;
72
+ return '\\' . Collection::class . '| ' . $ this ->reference ->getQualifiedUserClassName () . '[] ' ;
73
73
}
74
74
75
75
/**
@@ -99,32 +99,32 @@ public function body()
99
99
{
100
100
$ body = 'return $this->belongsToMany( ' ;
101
101
102
- $ body .= $ this ->reference ->getQualifiedUserClassName (). '::class ' ;
102
+ $ body .= $ this ->reference ->getQualifiedUserClassName () . '::class ' ;
103
103
104
104
if ($ this ->needsPivotTable ()) {
105
- $ body .= ', ' . Dumper::export ($ this ->pivotTable ());
105
+ $ body .= ', ' . Dumper::export ($ this ->pivotTable ());
106
106
}
107
107
108
108
if ($ this ->needsForeignKey ()) {
109
109
$ foreignKey = $ this ->parent ->usesPropertyConstants ()
110
- ? $ this ->reference ->getQualifiedUserClassName (). ':: ' . strtoupper ($ this ->foreignKey ())
110
+ ? $ this ->reference ->getQualifiedUserClassName () . ':: ' . strtoupper ($ this ->foreignKey ())
111
111
: $ this ->foreignKey ();
112
- $ body .= ', ' . Dumper::export ($ foreignKey );
112
+ $ body .= ', ' . Dumper::export ($ foreignKey );
113
113
}
114
114
115
115
if ($ this ->needsOtherKey ()) {
116
116
$ otherKey = $ this ->reference ->usesPropertyConstants ()
117
- ? $ this ->reference ->getQualifiedUserClassName (). ':: ' . strtoupper ($ this ->otherKey ())
117
+ ? $ this ->reference ->getQualifiedUserClassName () . ':: ' . strtoupper ($ this ->otherKey ())
118
118
: $ this ->otherKey ();
119
- $ body .= ', ' . Dumper::export ($ otherKey );
119
+ $ body .= ', ' . Dumper::export ($ otherKey );
120
120
}
121
121
122
122
$ body .= ') ' ;
123
123
124
124
$ fields = $ this ->getPivotFields ();
125
125
126
- if (! empty ($ fields )) {
127
- $ body .= "\n\t\t\t\t\t->withPivot( " . $ this ->parametrize ($ fields ). ') ' ;
126
+ if (!empty ($ fields )) {
127
+ $ body .= "\n\t\t\t\t\t->withPivot( " . $ this ->parametrize ($ fields ) . ') ' ;
128
128
}
129
129
130
130
if ($ this ->pivot ->usesTimestamps ()) {
@@ -173,7 +173,11 @@ protected function pivotTable()
173
173
*/
174
174
protected function needsForeignKey ()
175
175
{
176
- $ defaultForeignKey = $ this ->parentRecordName ().'_id ' ;
176
+ if ($ this ->parent ->config ('relation.options.show_key ' )) {
177
+ return true ;
178
+ }
179
+
180
+ $ defaultForeignKey = $ this ->parentRecordName () . '_id ' ;
177
181
178
182
return $ this ->foreignKey () != $ defaultForeignKey || $ this ->needsOtherKey ();
179
183
}
@@ -191,7 +195,12 @@ protected function foreignKey()
191
195
*/
192
196
protected function needsOtherKey ()
193
197
{
194
- $ defaultOtherKey = $ this ->referenceRecordName ().'_id ' ;
198
+
199
+ if ($ this ->parent ->config ('relation.options.show_key ' )) {
200
+ return true ;
201
+ }
202
+
203
+ $ defaultOtherKey = $ this ->referenceRecordName () . '_id ' ;
195
204
196
205
return $ this ->otherKey () != $ defaultOtherKey ;
197
206
}
@@ -241,10 +250,10 @@ private function parametrize($fields = [])
241
250
{
242
251
return (string ) implode (', ' , array_map (function ($ field ) {
243
252
$ field = $ this ->reference ->usesPropertyConstants ()
244
- ? $ this ->pivot ->getQualifiedUserClassName (). ':: ' . strtoupper ($ field )
253
+ ? $ this ->pivot ->getQualifiedUserClassName () . ':: ' . strtoupper ($ field )
245
254
: $ field ;
246
255
247
256
return Dumper::export ($ field );
248
257
}, $ fields ));
249
258
}
250
- }
259
+ }
0 commit comments