File tree Expand file tree Collapse file tree 5 files changed +35
-4
lines changed Expand file tree Collapse file tree 5 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 22
33All notable changes to ` laravel-cross-eloquent-search ` will be documented in this file
44
5+ ## 2.1.0 - 2021-08-09
6+
7+ - Support for Table prefixes
8+
59## 2.0.4 - 2021-05-03
610
711- Fix phpdoc comment format (credit to @gazben )
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ public function getQualifiedColumns(): Collection
8282 *
8383 * @return \Illuminate\Database\Eloquent\Model
8484 */
85- protected function getModel (): Model
85+ public function getModel (): Model
8686 {
8787 return $ this ->builder ->getModel ();
8888 }
Original file line number Diff line number Diff line change @@ -337,8 +337,10 @@ protected function makeSelects(ModelToSearchThrough $currentModel): array
337337 $ qualifiedKeyName = $ qualifiedOrderByColumnName = 'null ' ;
338338
339339 if ($ modelToSearchThrough === $ currentModel ) {
340- $ qualifiedKeyName = $ modelToSearchThrough ->getQualifiedKeyName ();
341- $ qualifiedOrderByColumnName = $ modelToSearchThrough ->getQualifiedOrderByColumnName ();
340+ $ prefix = $ modelToSearchThrough ->getModel ()->getConnection ()->getTablePrefix ();
341+
342+ $ qualifiedKeyName = $ prefix . $ modelToSearchThrough ->getQualifiedKeyName ();
343+ $ qualifiedOrderByColumnName = $ prefix . $ modelToSearchThrough ->getQualifiedOrderByColumnName ();
342344 }
343345
344346 return [
Original file line number Diff line number Diff line change @@ -71,6 +71,23 @@ public function it_can_count_the_results()
7171 $ this ->assertEquals (3 , $ count );
7272 }
7373
74+ /** @test */
75+ public function it_respects_table_prefixes ()
76+ {
77+ $ this ->initDatabase ('prefix ' );
78+
79+ $ postA = Post::create (['title ' => 'foo ' ]);
80+ $ postB = Post::create (['title ' => 'bar ' ]);
81+ $ videoA = Video::create (['title ' => 'foo ' ]);
82+ $ videoB = Video::create (['title ' => 'bar ' , 'subtitle ' => 'foo ' ]);
83+
84+ $ count = Search::add (Post::class, 'title ' )
85+ ->add (Video::class, ['title ' , 'subtitle ' ])
86+ ->count ('foo ' );
87+
88+ $ this ->assertEquals (3 , $ count );
89+ }
90+
7491 /** @test */
7592 public function it_can_search_for_a_phrase ()
7693 {
Original file line number Diff line number Diff line change 33namespace ProtoneMedia \LaravelCrossEloquentSearch \Tests ;
44
55use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Support \Facades \DB ;
67use Orchestra \Testbench \TestCase as OrchestraTestCase ;
78use PDO ;
89use ProtoneMedia \LaravelCrossEloquentSearch \ServiceProvider ;
@@ -22,6 +23,13 @@ public function setUp(): void
2223
2324 $ this ->app ['config ' ]->set ('app.key ' , 'base64:yWa/ByhLC/GUvfToOuaPD7zDwB64qkc/QkaQOrT5IpE= ' );
2425
26+ $ this ->initDatabase ();
27+ }
28+
29+ protected function initDatabase ($ prefix = '' )
30+ {
31+ DB ::purge ('mysql ' );
32+
2533 $ this ->app ['config ' ]->set ('database.connections.mysql ' , [
2634 'driver ' => 'mysql ' ,
2735 'url ' => env ('DATABASE_URL ' ),
@@ -33,7 +41,7 @@ public function setUp(): void
3341 'unix_socket ' => env ('DB_SOCKET ' , '' ),
3442 'charset ' => 'utf8mb4 ' ,
3543 'collation ' => 'utf8mb4_unicode_ci ' ,
36- 'prefix ' => '' ,
44+ 'prefix ' => $ prefix ,
3745 'prefix_indexes ' => true ,
3846 'strict ' => true ,
3947 'engine ' => null ,
You can’t perform that action at this time.
0 commit comments