protected function registerMacros(Router $router)
 {
     $router->macro('module', function ($module, $sortable = false) use($router) {
         $controller = ucfirst($module) . 'Controller';
         if ($sortable) {
             $router->patch("{$module}/changeOrder", $controller . '@changeOrder');
         }
         $router->resource($module, $controller);
     });
     $this->app['paginateroute']->registerMacros();
 }
 /**
  * Set up the generic resource routes + controller.
  *
  * @param Router $router
  * @return void
  */
 protected function enableGenericResourceRouting(Router $router)
 {
     $app = $this->app;
     $app->bind('eloquentjs.router', RouteRegistrar::class);
     $app->when(RouteRegistrar::class)->needs('$controller')->give(GenericController::class);
     $app->when(GenericController::class)->needs(Model::class)->give(function ($app) {
         if ($resource = $app['eloquentjs.router']->getCurrentResource()) {
             return $app->make($resource);
         }
     });
     $router->macro('eloquent', function ($uri, $resource, $options = []) use($app) {
         $app['eloquentjs.router']->addRoute($uri, $resource, $options);
     });
 }
Example #3
0
 /**
  * Register a custom macro.
  *
  * @param string $name
  * @param callable $macro
  * @return void 
  * @static 
  */
 public static function macro($name, $macro)
 {
     \Illuminate\Routing\Router::macro($name, $macro);
 }
Example #4
0
 /**
  * @param \Illuminate\Routing\Router $router
  */
 protected function registerMacros(Router $router)
 {
     $router->macro('redirect', function ($url, $action) use($router) {
         $router->get($url, function () use($action) {
             return redirect()->action($action);
         });
     });
     $router->macro('module', function ($slug, $className, $sortable = false) use($router) {
         if ($sortable) {
             $router->patch("{$slug}/changeOrder", "{$className}Controller@changeOrder");
         }
         $router->resource($slug, "{$className}Controller");
     });
     $router->macro('articleList', function ($technicalNamePrefix, $action) use($router) {
         $articles = app(ArticleRepository::class)->getWithTechnicalNameLike($technicalNamePrefix);
         $router->get(app()->getLocale() . '/' . fragment_slug("navigation.{$technicalNamePrefix}"), function () use($articles) {
             return redirect(route("{$articles->first()->technical_name}"));
         })->name($technicalNamePrefix);
         $articles->map(function ($article) use($technicalNamePrefix, $action, $router) {
             $router->get(app()->getLocale() . '/' . fragment_slug("navigation.{$technicalNamePrefix}") . '/' . $article->url, $action)->name("{$article->technical_name}");
         });
     });
 }
 /**
  * Register Router Macro called Instance
  * 플러그인에에서 등록한 route pattern 형태로 등록하여 instance route 를 찾을 수 있도록 하는
  * 매크로 등록
  *
  * @param Router $router to register macro
  *
  * @return void
  */
 protected function registerInstanceMacro(Router $router)
 {
     static $seq = 1;
     $instanceMacro = function ($key, Closure $callback, $routeOptions = null) use(&$seq) {
         $pattern = '{instanceGroup' . $seq++ . '}';
         $attributes = ['prefix' => $pattern, 'module' => $key, 'middleware' => ['access']];
         if ($routeOptions !== null and is_array($routeOptions)) {
             $routeOptions = array_except($routeOptions, ['prefix', 'middleware']);
             $attributes = array_merge($attributes, $routeOptions);
             if (isset($routeOptions['middleware'])) {
                 $attributes['middleware'] .= '|' . $routeOptions['middleware'];
             }
         }
         $this->group($attributes, $callback);
     };
     $router->macro('instance', $instanceMacro);
 }
 /**
  * Register Router Macro called Instance
  * 플러그인에에서 등록한 route pattern 형태로 등록하여 instance route 를 찾을 수 있도록 하는
  * 매크로 등록
  *
  * @param Router $router to register macro
  *
  * @return void
  */
 protected function registerInstanceMacro(Router $router)
 {
     $instanceMacro = function ($key, Closure $callback, $routeOptions = null) {
         $pattern = sprintf("%s%s%s", "{", preg_replace("/[@\\/]/", "_", $key), "}");
         $attributes = ['prefix' => $pattern, 'module' => $key, 'middleware' => ['access']];
         if ($routeOptions !== null and is_array($routeOptions)) {
             $routeOptions = array_except($routeOptions, ['prefix', 'middleware']);
             $attributes = array_merge($attributes, $routeOptions);
             if (isset($routeOptions['middleware'])) {
                 $attributes['middleware'] .= '|' . $routeOptions['middleware'];
             }
         }
         $this->group($attributes, $callback);
     };
     $router->macro('instance', $instanceMacro);
 }
 /**
  * Register Router Macro called Fixed
  * fixed 로 호출할 수 있는 Router 매크로를 등록하여
  * 플러그인 고유한 URL 을 가져갈 수 있도록 한다.
  *
  * @param Router $router to register macro
  *
  * @return void
  */
 protected function registerFixedMacro(Router $router)
 {
     $fixedMacro = function ($key, Closure $callback, $routeOptions = null) {
         $newKey = str_replace('@', '/', $key);
         $attributes = ['prefix' => config('xe.routing.fixedPrefix') . '/' . $newKey];
         if ($routeOptions !== null and is_array($routeOptions)) {
             $routeOptions = array_except($routeOptions, ['prefix']);
             $attributes = array_merge($attributes, $routeOptions);
         }
         $this->group($attributes, $callback);
     };
     $router->macro('fixed', $fixedMacro);
 }