Specify another public path

My Laravel application runs in a private folder, and I need to tell Laravel that the shared path is different. Today I updated the Laravel application from 4.2 to 5.0, and I can’t find where we are specifying the public path since the paths.php file no longer exists in Laravel 5.0 .

In laravel 4.2, we had the file /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', 

I do not use the Laravel 5.0 folder structure yet, any help would be greatly appreciated.

+5
source share
3 answers

Which worked flawlessly for me, the following three lines were added to public/index.php :

 $app->bind('path.public', function() { return __DIR__; }); 

This was answered by Laracast .

+13
source

I think it can be done in different ways, here is mine.

Create a new helper file. You can create it in the Services folder:

 # app/Services/helper.php if ( ! function_exists('private_path')){ function private_path($path = ''){ return app_path() . 'private/' } } 

A good place to import an auxiliary file is in the AppServiceProvider , which is located in app/Providers/AppServiceProvider.php . Use boot for this.

 public function boot() { include __dir__ . "/../Services/helper.php"; } 

Rename the folder from public to private and finally, you can call your own function from anywhere:

 $path = private_path(); 
+2
source

According to this post , in order to replace the original public path, we need to redefine the application paths:

 <?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'; } } 

This seems strange to me, and as mentioned in the post, it looks like we have taken a step back in Laravel functionality, I hope that they will change it in a future update.

0
source

Source: https://habr.com/ru/post/1213063/


All Articles