zoukankan      html  css  js  c++  java
  • laravel如何自定义一个路由文件

    1.自定义路由文件在项目的/app/Providers/RouteServiceProvider.php中定义

     2.如上图所示我们定义一个wap.php的路由文件(标记的代码就是路由注册的方法)

     1 <?php
     2 
     3 namespace AppProviders;
     4 
     5 use IlluminateFoundationSupportProvidersRouteServiceProvider as ServiceProvider;
     6 use IlluminateSupportFacadesRoute;
     7 
     8 class RouteServiceProvider extends ServiceProvider
     9 {
    10     /**
    11      * This namespace is applied to your controller routes.
    12      *
    13      * In addition, it is set as the URL generator's root namespace.
    14      *
    15      * @var string
    16      */
    17     protected $namespace = 'AppHttpControllers';
    18 
    19     /**
    20      * The path to the "home" route for your application.
    21      *
    22      * @var string
    23      */
    24     public const HOME = '/home';
    25 
    26     /**
    27      * Define your route model bindings, pattern filters, etc.
    28      *
    29      * @return void
    30      */
    31     public function boot()
    32     {
    33         //
    34 
    35         parent::boot();
    36     }
    37 
    38     /**
    39      * Define the routes for the application.
    40      *
    41      * @return void
    42      */
    43     public function map()
    44     {
    45         $this->mapApiRoutes();
    46 
    47         $this->mapWebRoutes();
    48 
    49         //测试注册路由
    50        $this->mapWapRoutes();
    51     }
    52 
    53     /**
    54      * Define the "web" routes for the application.
    55      *
    56      * These routes all receive session state, CSRF protection, etc.
    57      *
    58      * @return void
    59      */
    60     protected function mapWebRoutes()
    61     {
    62         Route::middleware('web')
    63              ->namespace($this->namespace)
    64              ->group(base_path('routes/web.php'));
    65     }
    66 
    67     /**
    68      * Define the "api" routes for the application.
    69      *
    70      * These routes are typically stateless.
    71      *
    72      * @return void
    73      */
    74     protected function mapApiRoutes()
    75     {
    76         Route::prefix('api')
    77              ->middleware('api')
    78              ->namespace($this->namespace)
    79              ->group(base_path('routes/api.php'));
    80     }
    81     #测试注册路由
    82     protected function mapWapRoutes(){
    83          Route::middleware('web')
    84          ->namespace($this->namespace)
    85          ->group(base_path('routes/wap.php'));
    86     }
    87 }

    3.自己测试路由信息

     3,浏览器测试(测试成功)

     或者直接在路由文件中引用需要的路由

    include __DIR__.'/delivery.php';
  • 相关阅读:
    H5应用加固防破解-js虚拟机保护方案浅谈
    Hijack chrome browser
    端口复用正向后门
    Django框架的一些漏洞
    07_简单的LISP加减乘除(基本计算器)
    git error:invalid path问题解决(win下)
    配置win10支持文件夹内区分大小写
    win10启用自带ubuntu虚拟机并升级至wsl2
    【进程调度】关于CPU的sockets、dies、cores、threads含义理解
    06_最长回文子串长度
  • 原文地址:https://www.cnblogs.com/yaoliuyang/p/12562141.html
Copyright © 2011-2022 走看看