@@ -67,29 +67,21 @@ 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- $ model ->getRelation ('related ' )::class,
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 ())
83- );
84- });
85- })->hydrate (function (Request $ request , Pivot $ model , mixed $ value ): void {
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 ())->withRelatableQuery (fn (Request $ request , Builder $ query , Pivot $ model ): Builder => $ this ->resolveRelatableQuery ($ request , $ model ->pivotParent )
76+ ->unless ($ this ->allowDuplicateRelations , fn (Builder $ query ): Builder => $ query ->whereNotIn (
77+ $ query ->getModel ()->getQualifiedKeyName (),
78+ $ this ->getRelation ($ model ->pivotParent )->select ($ query ->getModel ()->getQualifiedKeyName ())
79+ )))->hydrate (function (Request $ request , Pivot $ model , mixed $ value ): void {
8680 $ model ->setAttribute (
8781 $ this ->getRelation ($ model ->pivotParent )->getRelatedPivotKeyName (),
8882 $ value
8983 );
90- })->display (function (Model $ model ): ?string {
91- return $ this ->resolveDisplay ($ model );
92- }),
84+ })->display (fn (Model $ model ): ?string => $ this ->resolveDisplay ($ model )),
9385 ];
9486 }
9587
@@ -115,9 +107,7 @@ protected function resolveField(Request $request, Field $field): void
115107 }
116108
117109 if ($ field instanceof Relation) {
118- $ field ->resolveRouteKeyNameUsing (function () use ($ field ): string {
119- return Str::of ($ field ->getRelationName ())->singular ()->ucfirst ()->prepend ($ this ->getRouteKeyName ())->value ();
120- });
110+ $ field ->resolveRouteKeyNameUsing (fn (): string => Str::of ($ field ->getRelationName ())->singular ()->ucfirst ()->prepend ($ this ->getRouteKeyName ())->value ());
121111 }
122112
123113 parent ::resolveField ($ request , $ field );
@@ -146,9 +136,7 @@ public function withPivotFields(Closure $callback): static
146136 $ field ->setModelAttribute ($ attribute )
147137 ->name ($ attribute )
148138 ->id ($ attribute )
149- ->value (function () use ($ model , $ related , $ key ): mixed {
150- return $ related ->getRelation ($ this ->getRelation ($ model )->getPivotAccessor ())->getAttribute ($ key );
151- });
139+ ->value (fn (): mixed => $ related ->getRelation ($ this ->getRelation ($ model )->getPivotAccessor ())->getAttribute ($ key ));
152140 });
153141
154142 return $ fields ;
@@ -174,9 +162,7 @@ public function mergePivotValues(array $value): array
174162 {
175163 $ value = array_is_list ($ value ) ? array_fill_keys ($ value , []) : $ value ;
176164
177- return array_map (function (array $ pivot ): array {
178- return array_merge ($ this ->pivotValues , $ pivot );
179- }, $ value );
165+ return array_map (fn (array $ pivot ): array => array_merge ($ this ->pivotValues , $ pivot ), $ value );
180166 }
181167
182168 /**
0 commit comments