【发布时间】:2016-01-13 12:06:11
【问题描述】:
我遇到了一个问题。为路由创建文件夹并为不同的路由定义不同的文件。就像我有 3 种类型的用户。管理员,用户1,用户2。我想为路线创建 3 个不同的子文件夹。我搜索谷歌并实现这一点。但它不工作。 任何人都可以帮助我。
谢谢
<?php namespace App\Providers;
use Illuminate\Routing\Router;
use File;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider {
/**
* This namespace is applied to the controller routes in your routes file.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
//
}
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function($router)
{
foreach(File::allFiles(app_path().'/Http/Routes') as $route) {
require_once $route->getPathname();
}
});
}
}
【问题讨论】:
-
“文件夹”是什么意思?您想将路线保存在单独的文件/文件夹中吗?你想在 url 中有单独的“文件夹”吗?
标签: php file routing laravel-5