File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,7 +254,11 @@ public function augment($values)
254254 {
255255 $ single = $ this ->config ('max_items ' ) === 1 ;
256256
257- $ ids = Arr::wrap ($ values );
257+ $ ids = collect (Arr::wrap ($ values ))
258+ ->map (fn ($ id ) => $ id === 'current ' ? User::current ()?->id() : $ id )
259+ ->filter ()
260+ ->values ()
261+ ->all ();
258262
259263 $ query = (new OrderedQueryBuilder (User::query (), $ ids ))->whereIn ('id ' , $ ids );
260264
Original file line number Diff line number Diff line change @@ -60,6 +60,36 @@ public function it_augments_to_a_single_user_when_max_items_is_one()
6060 $ this ->assertEquals ('one@domain.com ' , $ augmented ->email ());
6161 }
6262
63+ #[Test]
64+ public function it_augments_the_current_user_when_value_is_the_current_string ()
65+ {
66+ $ this ->actingAs (Facades \User::find ('123 ' ));
67+
68+ $ augmented = $ this ->fieldtype (['max_items ' => 1 ])->augment ('current ' );
69+
70+ $ this ->assertInstanceOf (User::class, $ augmented );
71+ $ this ->assertEquals ('123 ' , $ augmented ->id ());
72+ }
73+
74+ #[Test]
75+ public function it_augments_the_current_user_to_a_query_builder_when_value_is_the_current_string ()
76+ {
77+ $ this ->actingAs (Facades \User::find ('123 ' ));
78+
79+ $ augmented = $ this ->fieldtype ()->augment ('current ' );
80+
81+ $ this ->assertInstanceOf (Builder::class, $ augmented );
82+ $ this ->assertEquals (['123 ' ], $ augmented ->get ()->map ->id ()->all ());
83+ }
84+
85+ #[Test]
86+ public function it_augments_to_null_when_value_is_the_current_string_and_no_user_is_authenticated ()
87+ {
88+ $ augmented = $ this ->fieldtype (['max_items ' => 1 ])->augment ('current ' );
89+
90+ $ this ->assertNull ($ augmented );
91+ }
92+
6393 #[Test]
6494 public function it_shallow_augments_to_a_collection_of_users ()
6595 {
You can’t perform that action at this time.
0 commit comments