Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/Eager/RelatedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Binaryk\LaravelRestify\Repositories\Repository;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

class RelatedCollection extends Collection
{
Expand All @@ -26,24 +25,24 @@ public function intoAssoc(): self

public function forEager(RestifyRequest $request): self
{
return $this->filter(fn($value, $key) => $value instanceof EagerField)
->filter(fn(Field $field) => $field->authorize($request))
return $this->filter(fn ($value, $key) => $value instanceof EagerField)
->filter(fn (Field $field) => $field->authorize($request))
->unique('attribute');
}

public function forManyToManyRelations(RestifyRequest $request): self
{
return $this->filter(function ($field) {
return $field instanceof BelongsToMany || $field instanceof MorphToMany;
})->filter(fn(EagerField $field) => $field->authorize($request));
})->filter(fn (EagerField $field) => $field->authorize($request));
}

public function mapIntoSortable(RestifyRequest $request): self
{
return $this->filter(fn(EagerField $field) => $field->isSortable())
return $this->filter(fn (EagerField $field) => $field->isSortable())
//Now we support only belongs to sort from related.
->filter(fn(EagerField $field) => $field instanceof BelongsTo)
->map(fn(BelongsTo $field) => SortableFilter::make()->usingBelongsTo($field));
->filter(fn (EagerField $field) => $field instanceof BelongsTo)
->map(fn (BelongsTo $field) => SortableFilter::make()->usingBelongsTo($field));
}

public function forShow(RestifyRequest $request, Repository $repository): self
Expand Down Expand Up @@ -85,6 +84,6 @@ public function mapIntoRelated(RestifyRequest $request)
public function authorized(RestifyRequest $request)
{
return $this->intoAssoc()
->filter(fn($key, $value) => $key instanceof EagerField ? $key->authorize($request) : true);
->filter(fn ($key, $value) => $key instanceof EagerField ? $key->authorize($request) : true);
}
}
2 changes: 0 additions & 2 deletions tests/Controllers/RepositoryIndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Binaryk\LaravelRestify\Tests\Controllers;

use Binaryk\LaravelRestify\Fields\HasMany;
use Binaryk\LaravelRestify\Tests\Fixtures\Company\Company;
use Binaryk\LaravelRestify\Tests\Fixtures\Company\CompanyRepository;
use Binaryk\LaravelRestify\Tests\Fixtures\Post\Post;
use Binaryk\LaravelRestify\Tests\Fixtures\Post\PostRepository;
use Binaryk\LaravelRestify\Tests\Fixtures\Post\RelatedCastWithAttributes;
use Binaryk\LaravelRestify\Tests\Fixtures\User\User;
use Binaryk\LaravelRestify\Tests\Fixtures\User\UserRepository;
use Binaryk\LaravelRestify\Tests\IntegrationTest;
use Illuminate\Foundation\Testing\RefreshDatabase;

Expand Down
4 changes: 2 additions & 2 deletions tests/Repositories/ActionLogRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function test_can_list_action_logs()
'name',
'user_id',
'actionable_type',
'actionable_id'
'actionable_id',
],
]
],
],
])->json('data');
}
Expand Down