@@ -76,6 +76,49 @@ public function test_can_search_using_belongs_to_field(): void
7676 ->assertJsonCount (2 , 'data ' );
7777 }
7878
79+ public function test_can_search_using_belongs_to_field_with_custom_foreign_key (): void
80+ {
81+ $ foreignUser = User::factory ()->create ([
82+ 'name ' => 'Curtis Dog ' ,
83+ ]);
84+
85+ Post::factory (4 )->create ([
86+ 'edited_by ' => $ foreignUser ->id ,
87+ ]);
88+
89+ $ john = User::factory ()->create ([
90+ 'name ' => 'John Doe ' ,
91+ ]);
92+
93+ Post::factory (2 )->create ([
94+ 'edited_by ' => $ john ->id ,
95+ ]);
96+
97+ PostRepository::$ related = [
98+ 'editor ' => BelongsTo::make ('editor ' , UserRepository::class)->searchable ([
99+ 'users.name ' ,
100+ ]),
101+ ];
102+
103+ $ this ->withoutExceptionHandling ();
104+ $ this ->getJson (PostRepository::route (query: ['search ' => 'John ' ]))
105+ ->assertJsonCount (2 , 'data ' );
106+ }
107+
108+ public function test_can_match_closure (): void
109+ {
110+ User::factory (4 )->create ();
111+
112+ UserRepository::$ match = [
113+ 'is_active ' => function ($ request , $ query ) {
114+ $ this ->assertInstanceOf (Request::class, $ request );
115+ $ this ->assertInstanceOf (Builder::class, $ query );
116+ },
117+ ];
118+
119+ $ this ->getJson ('users?is_active=true ' );
120+ }
121+
79122 public function test_can_match_custom_matcher (): void
80123 {
81124 User::factory (1 )->create ([
0 commit comments