22
33namespace Binaryk \LaravelRestify ;
44
5+ use Binaryk \LaravelRestify \Http \Controllers \RepositoryIndexController ;
56use Illuminate \Contracts \Debug \ExceptionHandler ;
67use Illuminate \Support \Facades \Route ;
78use Illuminate \Support \ServiceProvider ;
@@ -35,7 +36,9 @@ protected function registerRoutes()
3536 'middleware ' => config ('restify.middleware ' , []),
3637 ];
3738
38- $ this ->defaultRoutes ($ config );
39+ $ this ->defaultRoutes ($ config )
40+ ->registerPrefixed ($ config )
41+ ->registerIndexPrefixed ($ config );
3942 }
4043
4144 /**
@@ -51,6 +54,38 @@ public function defaultRoutes($config)
5154 return $ this ;
5255 }
5356
57+ /**
58+ * @param $config
59+ * @return $this
60+ */
61+ public function registerPrefixed ($ config )
62+ {
63+ collect (Restify::$ repositories )
64+ ->filter (fn ($ repository ) => $ repository ::prefix ())
65+ ->each (function ($ repository ) use ($ config ) {
66+ $ config ['prefix ' ] = $ repository ::prefix ();
67+ Route::group ($ config , function () {
68+ $ this ->loadRoutesFrom (__DIR__ .'/../routes/api.php ' );
69+ });
70+ });
71+
72+ return $ this ;
73+ }
74+
75+ public function registerIndexPrefixed ($ config )
76+ {
77+ collect (Restify::$ repositories )
78+ ->filter (fn ($ repository ) => $ repository ::indexPrefix ())
79+ ->each (function ($ repository ) use ($ config ) {
80+ $ config ['prefix ' ] = $ repository ::indexPrefix ();
81+ Route::group ($ config , function () {
82+ Route::get ('/{repository} ' , '\\' .RepositoryIndexController::class);
83+ });
84+ });
85+
86+ return $ this ;
87+ }
88+
5489 /**
5590 * Register Restify's custom exception handler.
5691 *
0 commit comments