[英]Multiple Route file in laravel 5/ multiple folder for routes
我陷入了一個問題。 為路由創建文件夾,並為不同的路由定義不同的文件。 像我有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();
}
});
}
}
它可以幫助其他人:
我有一個來自多個Laravel應用程序的4個子域的多租戶應用程序。 我想將每個子域的路由保留在單獨的文件中。
基於所接受的答案,在Laravel 5.4 I修改mapWebRoutes()
方法在RouteServiceProvider.php
如下:
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'domain' => 'subdomain1.yoursba.com',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/subdomain1Routes.php');
});
Route::group([
'middleware' => 'web',
'domain' => 'subdomain2.yoursba.com',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/subdomain2Routes.php');
});
}
我知道這已經晚了,但對於其他人,請查看此博客文章。 它可能正是您在尋找的東西https://arjunphp.com/multiple-routes-files-laravel-5/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.