Laravel 5 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30092279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 bundles
提问by Jan Ko?u?ník
I'm starting working with Laravel5 and I need to make app with some parts - e.g.:
我开始使用 Laravel5,我需要用某些部分制作应用程序 - 例如:
admin.example.com
app.example.com
example.com
It means: in app will have registered users access, in admin, there will have access administrators and example.com
will be for everybody.
这意味着:在应用程序中将具有注册用户访问权限,在管理员中将具有访问管理员权限,并且example.com
适用于所有人。
I know, that this can be done in Symfony 2 via bundles, but I'm not sure, what's the best way to make it in Laravel 5.
我知道,这可以通过捆绑包在 Symfony 2 中完成,但我不确定,在 Laravel 5 中实现它的最佳方法是什么。
Could you give me please your opinion about this?
你能告诉我你对这件事的看法吗?
回答by Pawel Bieszczad
In Laravel, bundles are called packages. You could also use a custom packageto easily split your application into modules. Here'sthe same question asked with some answers.
在 Laravel 中,bundle 被称为包。您还可以使用自定义包轻松地将您的应用程序拆分为多个模块。这是同样的问题,但有一些答案。
Hope this puts you on the right path.
希望这能让你走上正确的道路。
回答by Luceos
You can make hostname based routing using route groups. Using something like the following you can easily distinct between roles:
您可以使用路由组进行基于主机名的路由。使用类似以下内容,您可以轻松区分角色:
Route::group(['domain' => '{type?}.example.com'], function()
{
// .. do some logic based on type, eg change the controller
Route::get('user/{id}', function($type, $user_id)
{
//
});
});
Please note that this functionality is native to the core of Laravel.
请注意,此功能是 Laravel 核心的原生功能。