Skip to content

Commit

Permalink
Added the feature to return linkItems directly
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed May 29, 2024
1 parent 0024703 commit 2333ac3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

- Added the `priceGreaterThan`, `priceLessThan` and `priceBetween` methods to the ProductSearch class by [Matima](https://github.com/mahdirezaei-dev) in [#176](https://github.com/vanilophp/framework/pull/176)
- Added the `Macroable` trait to the `ProductSearch` class
- Added the possibility to retrieve the link items directly using `linkItems()` method as `Get::the($type)->linkItems()->of($model)`
- Added the `link_items` helper (shortcut to Get::the()->linkItems()
- Changed the offline payment gateway's icon from a circle to a plug+x

## 4.0.1
Expand Down
6 changes: 6 additions & 0 deletions src/Links/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 4.x Series

## Unreleased
##### 2024-XX-YY

- Added the possibility to retrieve the link items directly using `linkItems()` method as `Get::the($type)->linkItems()->of($model)`
- Added the `link_items` helper (shortcut to Get::the()->linkItems()

## 4.0.0
##### 2024-04-25

Expand Down
20 changes: 16 additions & 4 deletions src/Links/Query/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ public function of(Model $model): Collection
return $groups;
}

$links = collect();
$groups->each(function ($group) use ($links, $model) {
$links->push(
$result = collect();
if ('linkItems' === $this->wants) {
$groups->each(function ($group) use ($result, $model) {
$result->push(
...$group
->items
->reject(fn ($item) => $item->linkable_id === $model->id)
);
});

return $result;
}

$groups->each(function ($group) use ($result, $model) {
$result->push(
...$group
->items
->map
Expand All @@ -53,6 +65,6 @@ public function of(Model $model): Collection
);
});

return $links;
return $result;
}
}
7 changes: 7 additions & 0 deletions src/Links/Query/WantsLinksOrGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public function groups(): self

return $this;
}

public function linkItems(): self
{
$this->wants = 'linkItems';

return $this;
}
}
9 changes: 9 additions & 0 deletions src/Links/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ function links(string $type, string $property = null): Get
}
}

if (!function_exists('link_items')) {
function link_items(string $type, string $property = null): Get
{
$result = Get::the($type)->linkItems();

return null !== $property ? $result->basedOn($property) : $result;
}
}

if (!function_exists('link_groups')) {
function link_groups(string $type, string $property = null): Get
{
Expand Down

0 comments on commit 2333ac3

Please sign in to comment.