@@ -67,29 +67,22 @@ public function getRelation(Model $model): EloquentRelation
6767 public function fields (Request $ request ): array
6868 {
6969 return [
70- BelongsTo::make ($ this ->getRelatedName (), 'related ' , static function (Pivot $ model ): BelongsToRelation {
71- return $ model ->belongsTo (
72- get_class ($ model ->getRelation ('related ' )),
73- $ model ->getRelatedKey (),
74- $ model ->getForeignKey (),
75- 'related '
76- )->withDefault ();
77- })->withRelatableQuery (function (Request $ request , Builder $ query , Pivot $ model ): Builder {
78- return $ this ->resolveRelatableQuery ($ request , $ model ->pivotParent )
79- ->unless ($ this ->allowDuplicateRelations , function (Builder $ query ) use ($ model ): Builder {
80- return $ query ->whereNotIn (
81- $ query ->getModel ()->getQualifiedKeyName (),
82- $ this ->getRelation ($ model ->pivotParent )->select ($ query ->getModel ()->getQualifiedKeyName ())
70+ BelongsTo::make ($ this ->getRelatedName (), 'related ' , static fn (Pivot $ model ): BelongsToRelation => $ model ->belongsTo (
71+ $ model ->getRelation ('related ' )::class,
72+ $ model ->getRelatedKey (),
73+ $ model ->getForeignKey (),
74+ 'related '
75+ )->withDefault ())
76+ ->withRelatableQuery (fn (Request $ request , Builder $ query , Pivot $ model ): Builder => $ this ->resolveRelatableQuery ($ request , $ model ->pivotParent )
77+ ->unless ($ this ->allowDuplicateRelations , fn (Builder $ query ): Builder => $ query ->whereNotIn (
78+ $ query ->getModel ()->getQualifiedKeyName (),
79+ $ this ->getRelation ($ model ->pivotParent )->select ($ query ->getModel ()->getQualifiedKeyName ())
80+ )))->hydrate (function (Request $ request , Pivot $ model , mixed $ value ): void {
81+ $ model ->setAttribute (
82+ $ this ->getRelation ($ model ->pivotParent )->getRelatedPivotKeyName (),
83+ $ value
8384 );
84- });
85- })->hydrate (function (Request $ request , Pivot $ model , mixed $ value ): void {
86- $ model ->setAttribute (
87- $ this ->getRelation ($ model ->pivotParent )->getRelatedPivotKeyName (),
88- $ value
89- );
90- })->display (function (Model $ model ): ?string {
91- return $ this ->resolveDisplay ($ model );
92- }),
85+ })->display (fn (Model $ model ): ?string => $ this ->resolveDisplay ($ model )),
9386 ];
9487 }
9588
@@ -115,9 +108,9 @@ protected function resolveField(Request $request, Field $field): void
115108 }
116109
117110 if ($ field instanceof Relation) {
118- $ field ->resolveRouteKeyNameUsing (function () use ( $ field ): string {
119- return Str::of ($ field ->getRelationName ())->singular ()->ucfirst ()->prepend ($ this ->getRouteKeyName ())->value ();
120- } );
111+ $ field ->resolveRouteKeyNameUsing (
112+ fn (): string => Str::of ($ field ->getRelationName ())->singular ()->ucfirst ()->prepend ($ this ->getRouteKeyName ())->value ()
113+ );
121114 }
122115
123116 parent ::resolveField ($ request , $ field );
@@ -146,9 +139,7 @@ public function withPivotFields(Closure $callback): static
146139 $ field ->setModelAttribute ($ attribute )
147140 ->name ($ attribute )
148141 ->id ($ attribute )
149- ->value (function () use ($ model , $ related , $ key ): mixed {
150- return $ related ->getRelation ($ this ->getRelation ($ model )->getPivotAccessor ())->getAttribute ($ key );
151- });
142+ ->value (fn (): mixed => $ related ->getRelation ($ this ->getRelation ($ model )->getPivotAccessor ())->getAttribute ($ key ));
152143 });
153144
154145 return $ fields ;
@@ -170,13 +161,11 @@ public function getValueForHydrate(Request $request): mixed
170161 /**
171162 * Merge the pivot values.
172163 */
173- public function mergePivotValues (array $ value ): mixed
164+ public function mergePivotValues (array $ value ): array
174165 {
175166 $ value = array_is_list ($ value ) ? array_fill_keys ($ value , []) : $ value ;
176167
177- return array_map (function (array $ pivot ): array {
178- return array_merge ($ this ->pivotValues , $ pivot );
179- }, $ value );
168+ return array_map (fn (array $ pivot ): array => array_merge ($ this ->pivotValues , $ pivot ), $ value );
180169 }
181170
182171 /**
0 commit comments