我的Laravel应用程序在私人文件夹中工作,我需要告诉Laravel公共路径是不同的。 今天我已经将Laravel应用程序从4.2升级到5.0,我找不到指定公共路径since the paths.php file doesn't exist anymore in Laravel 5.0的位置。
在laravel 4.2中,我们有/bootstrap/paths.php
文件:
/*
|--------------------------------------------------------------------------
| Public Path
|--------------------------------------------------------------------------
|
| The public path contains the assets for your web application, such as
| your JavaScript and CSS files, and also contains the primary entry
| point for web requests into these applications from the outside.
|
*/
'public' => __DIR__.'/../../../public_html',
我还没有使用Laravel 5.0文件夹结构,非常感谢任何帮助。
答案 0 :(得分:13)
对我来说完美无缺的是在public/index.php
增加了以下三行:
$app->bind('path.public', function() {
return __DIR__;
});
这是在Laracast回答的。
答案 1 :(得分:2)
我认为这可以用不同的方式制作,这是我的。
创建一个新的帮助文件。您可以在Services
文件夹中创建它:
# app/Services/helper.php
if ( ! function_exists('private_path')){
function private_path($path = ''){
return app_path() . 'private/'
}
}
导入帮助文件的好地方是位于AppServiceProvider
的{{1}}。使用app/Providers/AppServiceProvider.php
执行此操作。
boot
将文件夹从public function boot()
{
include __dir__ . "/../Services/helper.php";
}
重命名为public
,最后您可以随时随地调用自己的功能:
private
答案 2 :(得分:0)
根据this post,要替换原始公共路径,我们需要覆盖应用程序路径:
<?php namespace App;
use Illuminate\Foundation\Application;
class MyApp extends Application {
protected $appPaths = array();
/**
* Create a new Illuminate application instance.
*
* @param array|null $appPaths
* @return \MyApp
*/
public function __construct($appPaths = null)
{
$this->registerBaseBindings();
$this->registerBaseServiceProviders();
$this->registerCoreContainerAliases();
if (!is_array($appPaths)) {
abort(500, '_construct requires paths array');
}
if (!isset($appPaths['base'])) {
abort(500, '_construct requires base path');
}
$this->appPaths = $appPaths;
$this->setBasePath($appPaths['base']);
}
/**
* Set the base path for the application.
*
* @param string $basePath
* @return $this
*/
public function setBasePath($basePath)
{
$this->basePath = $basePath;
$this->bindPathsInContainer();
return $this;
}
/**
* Bind all of the application paths in the container.
*
* @return void
*/
protected function bindPathsInContainer()
{
$this->instance('path', $this->path());
foreach (['base', 'config', 'database', 'lang', 'public', 'storage'] as $path)
{
$this->instance('path.'.$path, $this->{$path.'Path'}());
}
}
/**
* Get the path to the application "app" directory.
*
* @return string
*/
public function path()
{
return $this->basePath.'/app';
}
/**
* Get the base path of the Laravel installation.
*
* @return string
*/
public function basePath()
{
return $this->basePath;
}
/**
* Get the path to the application configuration files.
*
* @return string
*/
public function configPath()
{
if (isset($this->appPaths['config'])) {
return $this->appPaths['config'];
}
return $this->basePath.'/config';
}
/**
* Get the path to the database directory.
*
* @return string
*/
public function databasePath()
{
if (isset($this->appPaths['database'])) {
return $this->appPaths['database'];
}
return $this->basePath.'/database';
}
/**
* Get the path to the language files.
*
* @return string
*/
public function langPath()
{
if (isset($this->appPaths['lang'])) {
return $this->appPaths['lang'];
}
return $this->basePath.'/resources/lang';
}
/**
* Get the path to the public / web directory.
*
* @return string
*/
public function publicPath()
{
if (isset($this->appPaths['public'])) {
return $this->appPaths['public'];
}
return $this->basePath.'/public';
}
/**
* Get the path to the storage directory.
*
* @return string
*/
public function storagePath()
{
if (isset($this->appPaths['storage'])) {
return $this->appPaths['storage'];
}
return $this->basePath.'/storage';
}
}
这对我来说似乎很奇怪,并且正如帖子中提到的那样,感觉就像我们在Laravel的功能方面退了一步,我希望他们会在未来的更新中改变它。