Skip to content

Commit db3bb8f

Browse files
committed
fix: wip
2 parents 12568c3 + 20f1fc6 commit db3bb8f

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

src/Eager/Related.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Binaryk\LaravelRestify\Fields\EagerField;
66
use Binaryk\LaravelRestify\Filters\RelatedQuery;
77
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
8-
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
98
use Binaryk\LaravelRestify\Repositories\Repository;
109
use Binaryk\LaravelRestify\Traits\HasColumns;
1110
use Binaryk\LaravelRestify\Traits\Make;
@@ -107,7 +106,6 @@ public function resolve(RestifyRequest $request, Repository $repository): self
107106
return $this;
108107
}
109108

110-
111109
switch ($paginator) {
112110
case $paginator instanceof Collection:
113111
$this->value = $paginator;

src/Fields/BelongsToMany.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Binaryk\LaravelRestify\Repositories\Repository;
1111
use Closure;
1212
use Illuminate\Auth\Access\AuthorizationException;
13-
use Illuminate\Http\Request;
1413

1514
class BelongsToMany extends EagerField
1615
{
@@ -63,8 +62,8 @@ public function resolve($repository, $attribute = null)
6362
)
6463
->withPivots(
6564
PivotsCollection::make($this->pivotFields)
66-
->map(fn(Field $field) => clone $field)
67-
->filter(fn(Field $field) => ! $field->isHidden(app(RestifyRequest::class)))
65+
->map(fn (Field $field) => clone $field)
66+
->filter(fn (Field $field) => ! $field->isHidden(app(RestifyRequest::class)))
6867
->resolveFromPivot($item->pivot)
6968
)
7069
->eager($this);

src/Repositories/Repository.php

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Binaryk\LaravelRestify\Http\Controllers\RestResponse;
1616
use Binaryk\LaravelRestify\Http\Requests\RepositoryStoreBulkRequest;
1717
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
18-
use Binaryk\LaravelRestify\MCP\Concerns\HasMcpTools;
1918
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
2019
use Binaryk\LaravelRestify\Models\Concerns\HasActionLogs;
2120
use Binaryk\LaravelRestify\Models\CreationAware;
@@ -430,10 +429,10 @@ public function resolveShowAttributes(RestifyRequest $request)
430429
{
431430
$fields = $this->collectFields($request)
432431
->forShow($request, $this)
433-
->filter(fn(Field $field) => $field->authorize($request))
434-
->each(fn(Field $field) => $field->resolveForShow($this))
435-
->map(fn(Field $field) => $field->serializeToValue($request))
436-
->mapWithKeys(fn($value) => $value)
432+
->filter(fn (Field $field) => $field->authorize($request))
433+
->each(fn (Field $field) => $field->resolveForShow($this))
434+
->map(fn (Field $field) => $field->serializeToValue($request))
435+
->mapWithKeys(fn ($value) => $value)
437436
->all();
438437

439438
if ($this instanceof Mergeable) {
@@ -498,17 +497,17 @@ public function resolveIndexAttributes($request)
498497
->collectFields($request)
499498
->when(
500499
$this->hasCustomColumns(),
501-
fn(FieldCollection $fields) => $fields->inList($this->getColumns())
500+
fn (FieldCollection $fields) => $fields->inList($this->getColumns())
502501
)
503502
->forIndex($request, $this)
504-
->filter(fn(Field $field) => $field->authorize($request))
503+
->filter(fn (Field $field) => $field->authorize($request))
505504
->when(
506505
$this->eagerState,
507-
fn($items) => $items->filter(fn(Field $field) => ! $field instanceof EagerField)
506+
fn ($items) => $items->filter(fn (Field $field) => ! $field instanceof EagerField)
508507
)
509-
->each(fn(Field $field) => $field->resolveForIndex($this))
510-
->map(fn(Field $field) => $field->serializeToValue($request))
511-
->mapWithKeys(fn($value) => $value)
508+
->each(fn (Field $field) => $field->resolveForIndex($this))
509+
->map(fn (Field $field) => $field->serializeToValue($request))
510+
->mapWithKeys(fn ($value) => $value)
512511
->all();
513512
}
514513

@@ -542,10 +541,10 @@ public function resolveShowPivots(RestifyRequest $request): array
542541
}
543542

544543
return $pivots
545-
->filter(fn(Field $field) => $field->authorize($request))
546-
->each(fn(Field $field) => $field->resolve($this))
547-
->map(fn(Field $field) => $field->serializeToValue($request))
548-
->mapWithKeys(fn($value) => $value)
544+
->filter(fn (Field $field) => $field->authorize($request))
545+
->each(fn (Field $field) => $field->resolve($this))
546+
->map(fn (Field $field) => $field->serializeToValue($request))
547+
->mapWithKeys(fn ($value) => $value)
549548
->all();
550549
}
551550

@@ -572,7 +571,7 @@ public function resolveRelationships($request): array
572571
->mapIntoRelated($request, $this)
573572
->unserialized($request, $this)
574573
->when($this->isForMcp(), fn (RelatedCollection $collection) => $collection->forMcp($request, $this))
575-
->map(fn(Related $related) => $related->resolve($request, $this)->getValue())
574+
->map(fn (Related $related) => $related->resolve($request, $this)->getValue())
576575
->map(function (mixed $items) {
577576
if ($items instanceof Collection) {
578577
return $items->filter()->values();
@@ -640,13 +639,13 @@ public function indexAsArray(RestifyRequest $request): array
640639
return $repository->authorizedToShow($request);
641640
})->values();
642641

643-
$data = $items->map(fn(self $repository) => $repository->serializeForIndex($request));
642+
$data = $items->map(fn (self $repository) => $repository->serializeForIndex($request));
644643

645644
return $this->filter([
646645
'meta' => $this->when(
647646
$meta = $this->resolveIndexMainMeta(
648647
$request,
649-
$models = $items->map(fn(self $repository) => $repository->resource),
648+
$models = $items->map(fn (self $repository) => $repository->resource),
650649
[
651650
'current_page' => $paginator->currentPage(),
652651
'from' => $paginator->firstItem(),
@@ -732,14 +731,14 @@ public function store(RestifyRequest $request)
732731
}
733732
}
734733

735-
$fields->each(fn(Field $field) => $field->invokeAfter($request, $this->resource));
734+
$fields->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
736735

737736
$this
738737
->collectFields($request)
739738
->forStore($request, $this)
740739
->withActions($request, $this)
741740
->authorizedStore($request)
742-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
741+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
743742
});
744743

745744
if (method_exists(static::class, 'stored')) {
@@ -768,14 +767,14 @@ public function storeBulk(RepositoryStoreBulkRequest $request)
768767

769768
$this->resource->save();
770769

771-
$fields->each(fn(Field $field) => $field->invokeAfter($request, $this->resource));
770+
$fields->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
772771

773772
$this
774773
->collectFields($request)
775774
->forStoreBulk($request, $this)
776775
->withActions($request, $this, $row)
777776
->authorizedUpdateBulk($request)
778-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
777+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
779778

780779
return $this->resource;
781780
});
@@ -802,15 +801,15 @@ public function update(RestifyRequest $request, $repositoryId)
802801

803802
return $fields;
804803
})->each(
805-
fn(Field $field) => $field->invokeAfter($request, $this->resource)
804+
fn (Field $field) => $field->invokeAfter($request, $this->resource)
806805
);
807806

808807
$this
809808
->collectFields($request)
810809
->forUpdate($request, $this)
811810
->withActions($request, $this)
812811
->authorizedUpdate($request)
813-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
812+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
814813

815814
return data($this->serializeForShow($request));
816815
}
@@ -822,7 +821,7 @@ public function patch(RestifyRequest $request, $repositoryId)
822821
DB::transaction(function () use ($request, $keys) {
823822
$fields = $this->collectFields($request)
824823
->filter(
825-
fn(Field $field) => in_array($field->attribute, $keys),
824+
fn (Field $field) => in_array($field->attribute, $keys),
826825
)
827826
->forUpdate($request, $this)
828827
->withoutActions($request, $this)
@@ -841,18 +840,18 @@ public function patch(RestifyRequest $request, $repositoryId)
841840

842841
return $fields;
843842
})->each(
844-
fn(Field $field) => $field->invokeAfter($request, $this->resource)
843+
fn (Field $field) => $field->invokeAfter($request, $this->resource)
845844
);
846845

847846
$this
848847
->collectFields($request)
849848
->filter(
850-
fn(Field $field) => in_array($field->attribute, $keys),
849+
fn (Field $field) => in_array($field->attribute, $keys),
851850
)
852851
->forUpdate($request, $this)
853852
->withActions($request, $this)
854853
->authorizedPatch($request)
855-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource));
854+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
856855

857856
return data($this->serializeForShow($request));
858857
}
@@ -873,7 +872,7 @@ public function updateBulk(RestifyRequest $request, $repositoryId, int $row)
873872
->forUpdateBulk($request, $this)
874873
->withActions($request, $this, $row)
875874
->authorizedUpdateBulk($request)
876-
->each(fn(Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
875+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource, $row));
877876

878877
return response()->json();
879878
}
@@ -898,7 +897,7 @@ public function attach(RestifyRequest $request, $repositoryId, Collection $pivot
898897
$eagerField = $this->authorizeBelongsToMany($request)->belongsToManyField($request);
899898

900899
DB::transaction(function () use ($request, $pivots, $eagerField) {
901-
$fields = $eagerField->collectPivotFields()->filter(fn(
900+
$fields = $eagerField->collectPivotFields()->filter(fn (
902901
$pivotField
903902
) => $request->has($pivotField->attribute))->values();
904903

@@ -942,7 +941,7 @@ public function detach(RestifyRequest $request, $repositoryId, Collection $pivot
942941

943942
$deleted = DB::transaction(function () use ($pivots, $eagerField, $request) {
944943
return $pivots
945-
->map(fn($pivot) => $eagerField->authorizeToDetach($request, $pivot) && $pivot->delete());
944+
->map(fn ($pivot) => $eagerField->authorizeToDetach($request, $pivot) && $pivot->delete());
946945
});
947946

948947
return data($deleted, 204);
@@ -985,7 +984,7 @@ public function allowToAttach(RestifyRequest $request, Collection $attachers): s
985984
{
986985
$methodGuesser = 'attach'.Str::studly($request->relatedRepository);
987986

988-
$attachers->each(fn($model) => $this->authorizeToAttach($request, $methodGuesser, $model));
987+
$attachers->each(fn ($model) => $this->authorizeToAttach($request, $methodGuesser, $model));
989988

990989
return $this;
991990
}
@@ -1003,7 +1002,7 @@ public function allowToDetach(RestifyRequest $request, Collection $attachers): s
10031002
{
10041003
$methodGuesser = 'detach'.Str::studly($request->relatedRepository);
10051004

1006-
$attachers->each(fn($model) => $this->authorizeToDetach($request, $methodGuesser, $model));
1005+
$attachers->each(fn ($model) => $this->authorizeToDetach($request, $methodGuesser, $model));
10071006

10081007
return $this;
10091008
}
@@ -1107,7 +1106,7 @@ public function serializeForShow(RestifyRequest $request): array
11071106
$this->request = $request;
11081107

11091108
return $this->filter([
1110-
'id' => $this->when(optional($this->resource)?->getKey(), fn() => $this->getId($request)),
1109+
'id' => $this->when(optional($this->resource)?->getKey(), fn () => $this->getId($request)),
11111110
'type' => $this->when($type = $this->getType($request), $type),
11121111
'attributes' => $request->isShowRequest() ? $this->resolveShowAttributes($request) : $this->resolveIndexAttributes($request),
11131112
'relationships' => $this->when(value($related = $this->resolveRelationships($request)), $related),
@@ -1175,7 +1174,7 @@ private function modelAttributes(?Request $request = null): Collection
11751174
*/
11761175
protected static function fillFields(RestifyRequest $request, Model $model, Collection $fields)
11771176
{
1178-
return $fields->map(fn(Field $field) => $field->fillAttribute($request, $model));
1177+
return $fields->map(fn (Field $field) => $field->fillAttribute($request, $model));
11791178
}
11801179

11811180
protected static function fillBulkFields(
@@ -1243,14 +1242,14 @@ public function restifyjsSerialize(RestifyRequest $request): array
12431242
'match' => static::collectFilters('matches'),
12441243
'searchables' => static::collectFilters('searchables'),
12451244
'actions' => $this->resolveActions($request)
1246-
->filter(fn(mixed $action) => $action instanceof Action)
1247-
->filter(fn(Action $action) => $action->isShownOnIndex(
1245+
->filter(fn (mixed $action) => $action instanceof Action)
1246+
->filter(fn (Action $action) => $action->isShownOnIndex(
12481247
$request,
12491248
$this
12501249
))->values(),
12511250
'getters' => $this->resolveGetters($request)
1252-
->filter(fn(mixed $action) => $action instanceof Getter)
1253-
->filter(fn(Getter $action) => $action->isShownOnIndex(
1251+
->filter(fn (mixed $action) => $action instanceof Getter)
1252+
->filter(fn (Getter $action) => $action->isShownOnIndex(
12541253
$request,
12551254
$this
12561255
))->values(),

0 commit comments

Comments
 (0)