diff --git a/src/Serverfireteam/Panel/Commands/PanelCommand.php b/src/Serverfireteam/Panel/Commands/PanelCommand.php index b8aed58..98df860 100644 --- a/src/Serverfireteam/Panel/Commands/PanelCommand.php +++ b/src/Serverfireteam/Panel/Commands/PanelCommand.php @@ -42,19 +42,19 @@ public function handle() $this->info('** publishing panel assets'); $this->call('vendor:publish', [ - '--tag' => 'public', + '--tag' => 'panelpublic', '--quiet' => null //'--force' => 1 ]); $this->info('** publishing panel config'); $this->call('vendor:publish', [ - '--tag' => 'config', + '--tag' => 'panelconfig', '--quiet' => null //'--force' => 1 ]); $this->info('** publishing panel views'); $this->call('vendor:publish', [ - '--tag' => 'views', + '--tag' => 'panelviews', '--quiet' => null //'--force' => 1 ]); diff --git a/src/Serverfireteam/Panel/PanelServiceProvider.php b/src/Serverfireteam/Panel/PanelServiceProvider.php index 2918504..8d5bbe7 100644 --- a/src/Serverfireteam/Panel/PanelServiceProvider.php +++ b/src/Serverfireteam/Panel/PanelServiceProvider.php @@ -103,12 +103,12 @@ public function register() $this->publishes([ __DIR__ . '/../../../public' => public_path('packages/serverfireteam/panel') - ], 'public'); + ], 'panelpublic'); $this->publishes([ __DIR__.'/config/panel.php' => config_path('panel.php'), __DIR__.'/config/elfinder.php' => config_path('elfinder.php'), - ], 'config'); + ], 'panelconfig'); } public function boot() @@ -116,7 +116,7 @@ public function boot() $this->loadViewsFrom(__DIR__.'/../../views', 'panelViews'); $this->publishes([ __DIR__.'/../../views' => base_path('resources/views/vendor/panelViews'), - ], 'views'); + ], 'panelviews'); include __DIR__."/../../routes.php"; diff --git a/src/controllers/MainController.php b/src/controllers/MainController.php index 2693e50..59f55b5 100644 --- a/src/controllers/MainController.php +++ b/src/controllers/MainController.php @@ -9,39 +9,62 @@ use \Serverfireteam\Panel\libs\PanelElements; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\Request; class MainController extends Controller { public function entityUrl($entity, $methods){ + $uri = Request::path(); + // Get route collection + $routes = collect(Route::getRoutes()->getRoutes())->reduce(function ($carry = [], $route) { + starts_with($route->uri(), 'panel/{entity}') ?: $carry[] = $route; + return $carry; + }); + try { + // If we find a match, take the user there. + foreach ($routes as $route){ + if ($uri == $route->uri()){ + $controller_path = $route->getAction()['controller']; + $controller_action = explode('@',$controller_path); + $controller = \App::make($controller_action[0]); + return $controller->callAction($controller_action[1], array()); + break; + } + } + } + catch (Exception $e){ + // Otherwise, we didn't find a match so take the user to the admin page. + return redirect('/panel'); + } - $appHelper = new libs\AppHelper(); + $appHelper = new libs\AppHelper(); if ( \Links::isMain($entity)){ $controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller'; - } else { + } else { $panel_path = \Config::get('panel.controllers'); - if ( isset($panel_path) ){ - $controller_path = '\\'.$panel_path.'\\'.$entity.'Controller'; - } else { - $controller_path = $appHelper->getNameSpace().'Http\Controllers\\'.$entity.'Controller'; - } - } - - try{ - $controller = \App::make($controller_path); - }catch(\Exception $ex){ - throw new \Exception("Controller not found ( $controller_path ) "); - } + if ( isset($panel_path) ){ + $controller_path = '\\'.$panel_path.'\\'.$entity.'Controller'; + } else { + $controller_path = $appHelper->getNameSpace().'Http\Controllers\\'.$entity.'Controller'; + } + } + + try{ + $controller = \App::make($controller_path); + }catch(\Exception $ex){ + throw new \Exception("Controller not found ( $controller_path ) "); + } + if (!method_exists($controller, $methods)){ + throw new \Exception('Controller does not implement the CrudController methods!'); + } else { + return $controller->callAction($methods, array('entity' => $entity)); + } - if (!method_exists($controller, $methods)){ - throw new \Exception('Controller does not implement the CrudController methods!'); - } else { - return $controller->callAction($methods, array('entity' => $entity)); } - -} }