-->

PHP资讯

您的当前位置:首页 > 资讯 > Laravel框架

laravel框架搭建

2019-05-22 09:20:31  来源:admin 点击:617

1.Laravel除了使用默认的路由文件来定义路由,还可以使用自己的路由文件。创建自己的路由文件步骤如下:
在routes文件夹下创建自己的路由文件,例如admin.php:

创建路由文件

image.png

2.在app/Providers/RouteServiceProvider服务提供者中注册该路由文件,添加mapAdminRoutes方法并且修改map方法,具体如下所示:

/**

 * Define the "admin" routes for the application.

 */

protected function mapPcRoutes()

{

    Route::middleware('pc') //中间件

        ->namespace($this->namespace) //命名空间

        ->group(base_path('routes/pc.php'));

}

3.增加路由注入

public function map()

{

    $this->mapApiRoutes();

    $this->mapWebRoutes();

    $this->mapPcRoutes();

}

3.在路由文件admin.php中添加路由:

<?php

Route::group(['prefix' => 'pc', 'namespace' => 'Pc'], function() {

    Route::get('index', 'IndexController@index');

    Route::get('test', function() {

        return 'your route is ready';

    });

});

4.有中间件的加'middleware' => ['pc'],中间件过滤

<?php

Route::group(['prefix' => 'pc', 'namespace' => 'Pc','middleware' => ['pc']], function() {

    Route::get('index', 'IndexController@index');

    Route::get('test', function() {

        return 'your route is ready';

    });

});

image.png

相关文章更多 >

© 2024版权所有 水水网

电话:171780793