From bafecaeb04c51a86df8ca5008545226988960905 Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 18 Jun 2019 14:39:35 +0430 Subject: [PATCH 1/2] update MainController - check if has any route with current uri --- src/controllers/MainController.php | 63 ++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 20 deletions(-) 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)); } - -} } From fd47b864fce008cceb1acdb458fc51d510963e78 Mon Sep 17 00:00:00 2001 From: Reza Date: Thu, 20 Jun 2019 14:45:50 +0430 Subject: [PATCH 2/2] change vendor:publish tag names --- src/Serverfireteam/Panel/Commands/PanelCommand.php | 6 +++--- src/Serverfireteam/Panel/PanelServiceProvider.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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";