[英]Laravel named route to directory
Is there possible way to make named route in laravel for directory? 有没有办法在laravel中为目录创建命名路由? For example I have directory named stats in public directory, and I wanna to be able to call it as route('page.stats'). 例如,我在公共目录中有一个名为stats的目录,我希望能够将其称为route('page.stats')。
Your thinking is not frameworklike. 您的想法不是框架式的。 In this case I suggest you to move out the resorce (probably index.php) from public to somewhere else and then call it from the controller. 在这种情况下,我建议您将资源(可能是index.php)从公共位置移到其他位置,然后从控制器中调用它。
If you still want to run it under this path, here is a solvation. 如果您仍然想在此路径下运行它,则这里有一个解决方法。 In the routing file add: 在路由文件中添加:
Route::get('page/stats', function () {
return require public_path('stats/index.php');
});
I think you should move out this files from public
folder and under app
folder you can create a Helper
folder and move them to there and you have to declare path to this Helper
folder if you are using 3rd party softwares as classes. 我想你应该这样文件从迁出public
文件夹下的app
文件夹,您可以创建一个Helper
文件夹,并将其移动到那里,你必须声明这条道路Helper
,如果你使用的是第三方软件如类文件夹。 In composer.json
file under autoload
array you can declare classes or files. 在autoload
数组下的composer.json
文件中,您可以声明类或文件。 If you are using 3rd party softwares as a single file and want to use them every request you can add as a file
and include easily. 如果您将第三方软件作为单个文件使用,并且希望使用它们,那么您可以将每个请求添加为file
并轻松添加。
My composer.json
file structure is like that : 我的composer.json
文件结构是这样的:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files" : [
"app/Helpers.php",
"app/Helpers/company-helpers.php"
]
}
I think you should use like this otherwise using 3rd party softwares under public
folder is not good thing fot using in MVC design pattern. 我想下你应该使用这样以其它方式使用第三方软件public
文件夹不是FOT使用MVC设计模式好事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.