laravel框架搭建
所属分类: Laravel框架 2019-05-22 09:20:31 编辑:admin 浏览次数 1191 次
1.Laravel除了使用默认的路由文件来定义路由,还可以使用自己的路由文件。创建自己的路由文件步骤如下:
在routes文件夹下创建自己的路由文件,例如admin.php:
创建路由文件
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';
});
});
猜你喜欢
- laravel常用命令总结 2018-07-22
- laravel的条件查询where的且、或关系总结 2018-07-24
- laravel查询总结 2018-07-27
- laravel查询操作小技巧 2018-07-28
- laravel安装composer依赖Excel 2018-07-30
- laravel 如何引入自己的类库和函数 2018-07-30