Skip to content

Commit 4e55b22

Browse files
committed
wip
1 parent 91b1417 commit 4e55b22

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

docs/docs/3.0/repository-pattern/repository-pattern.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -671,19 +671,6 @@ As the store bulk, the update bulk uses DB transaction to perform the action. So
671671
->updateBulkRules('required', Rule::in('posts:id'))
672672
```
673673

674-
Sometimes you may need to know the current row in `fieldsForStoreBulk` for some complex validations, this will be passed for bulk update and store:
675-
676-
```php
677-
public function fieldsForStoreBulk(RestifyRequest $request, int $bulkRow)
678-
{
679-
return [
680-
Field::new()->rules(Rule::unique('users')->where(function ($query) use ($request, $bulkRow) {
681-
return $query->where('account_id', data_get($request->all(), $bulkRow . '.account_id'));
682-
}))
683-
];
684-
}
685-
```
686-
687674
### Bulk Payload
688675

689676
The payload for a bulk update should contain an array of objects. Each object SHOULD contain an `id` key, based on this, the Laravel Restify will find the entity:

src/Repositories/Repository.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ public function filters(RestifyRequest $request)
235235

236236
/**
237237
* @param RestifyRequest $request
238-
* @param int|null $bulkRow
239238
* @return FieldCollection
240239
*/
241-
public function collectFields(RestifyRequest $request, int $bulkRow = null)
240+
public function collectFields(RestifyRequest $request)
242241
{
243242
$method = 'fields';
244243

@@ -266,7 +265,7 @@ public function collectFields(RestifyRequest $request, int $bulkRow = null)
266265
$method = 'fieldsForUpdateBulk';
267266
}
268267

269-
$fields = FieldCollection::make(array_values($this->filter($this->{$method}($request, $bulkRow))));
268+
$fields = FieldCollection::make(array_values($this->filter($this->{$method}($request))));
270269

271270
if ($this instanceof Mergeable) {
272271
$fillable = collect($this->resource->getFillable())
@@ -300,9 +299,9 @@ private function updateFields(RestifyRequest $request)
300299
->authorizedUpdate($request);
301300
}
302301

303-
private function updateBulkFields(RestifyRequest $request, int $bulkRow)
302+
private function updateBulkFields(RestifyRequest $request)
304303
{
305-
return $this->collectFields($request, $bulkRow)
304+
return $this->collectFields($request)
306305
->forUpdateBulk($request, $this)
307306
->authorizedUpdateBulk($request);
308307
}
@@ -314,9 +313,9 @@ private function storeFields(RestifyRequest $request)
314313
->authorizedStore($request);
315314
}
316315

317-
private function storeBulkFields(RestifyRequest $request, int $bulkRow)
316+
private function storeBulkFields(RestifyRequest $request)
318317
{
319-
return $this->collectFields($request, $bulkRow)
318+
return $this->collectFields($request)
320319
->forStoreBulk($request, $this)
321320
->authorizedStore($request);
322321
}
@@ -621,17 +620,13 @@ public function storeBulk(RepositoryStoreBulkRequest $request)
621620
->map(function (array $input, $row) use ($request) {
622621
$this->resource = static::newModel();
623622

624-
$request->merge([
625-
'bulk_row' => $row,
626-
]);
627-
628623
static::fillBulkFields(
629-
$request, $this->resource, $this->storeBulkFields($request, $row), $row
624+
$request, $this->resource, $this->storeBulkFields($request), $row
630625
);
631626

632627
$this->resource->save();
633628

634-
$this->storeBulkFields($request, $row)->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
629+
$this->storeBulkFields($request)->each(fn (Field $field) => $field->invokeAfter($request, $this->resource));
635630

636631
return $this->resource;
637632
});
@@ -662,7 +657,7 @@ public function update(RestifyRequest $request, $repositoryId)
662657

663658
public function updateBulk(RestifyRequest $request, $repositoryId, int $row)
664659
{
665-
$fields = $this->updateBulkFields($request, $row);
660+
$fields = $this->updateBulkFields($request);
666661

667662
static::fillBulkFields($request, $this->resource, $fields, $row);
668663

@@ -739,11 +734,11 @@ public function allowToStore(RestifyRequest $request, $payload = null): self
739734
return $this;
740735
}
741736

742-
public function allowToBulkStore(RestifyRequest $request, $payload = null): self
737+
public function allowToBulkStore(RestifyRequest $request, $payload = null, $row = null): self
743738
{
744739
static::authorizeToStoreBulk($request);
745740

746-
$validator = static::validatorForStoringBulk($request, $payload);
741+
$validator = static::validatorForStoringBulk($request, $payload, $row);
747742

748743
$validator->validate();
749744

tests/Controllers/RepositoryStoreBulkControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function test_basic_validation_works()
2222
'title' => null,
2323
],
2424
])
25+
->dump()
2526
->assertStatus(400)
2627
->assertJson([
2728
'errors' => [

0 commit comments

Comments
 (0)