Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/Fieldtypes/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ public function augment($values)
{
$single = $this->config('max_items') === 1;

$ids = Arr::wrap($values);
$ids = collect(Arr::wrap($values))
->map(fn ($id) => $id === 'current' ? User::current()?->id() : $id)
->filter()
->values()
->all();

$query = (new OrderedQueryBuilder(User::query(), $ids))->whereIn('id', $ids);

Expand Down
11 changes: 11 additions & 0 deletions tests/Fieldtypes/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public function it_augments_to_a_single_user_when_max_items_is_one()
$this->assertEquals('one@domain.com', $augmented->email());
}

#[Test]
public function it_augments_the_current_user_when_value_is_the_current_string()
{
$this->actingAs(Facades\User::find('123'));

$augmented = $this->fieldtype(['max_items' => 1])->augment('current');

$this->assertInstanceOf(User::class, $augmented);
$this->assertEquals('123', $augmented->id());
}

#[Test]
public function it_shallow_augments_to_a_collection_of_users()
{
Expand Down
Loading