領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0KB

  1. <?php
  2. namespace App\Util;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Support\Str;
  5. class RouteHelper
  6. {
  7. const ENTRY = 'entry';
  8. static public function get(string $url, string $class)
  9. {
  10. return Route::get($url, [$class, self::ENTRY])->name(self::routeName($class));
  11. }
  12. static public function post(string $url, string $class)
  13. {
  14. return Route::post($url, [$class, self::ENTRY])->name(self::routeName($class));
  15. }
  16. static public function server(string $url, string $class)
  17. {
  18. return Route::post($url, [$class, self::ENTRY])->name(self::routeName($class));
  19. }
  20. static public function routeName(string $class)
  21. {
  22. $ele = explode('\\', $class);
  23. $controllerName = array_pop($ele);
  24. $groupName = array_pop($ele);
  25. $routeName = Str::replaceLast('Controller', '', $groupName . $controllerName);
  26. return $routeName;
  27. }
  28. static public function webRoute(string $route)
  29. {
  30. return Str::replaceFirst('/api', '', $route);
  31. }
  32. }