With this "new"/"better" method, you don't put that in
/public/index.php. In fact, you don't put that function anywhere.
In the simplest terms possible (basically, duplicating the correct [though, not accepted] answer on StackOverflow):
1.) In
/bootstrap/app.php (not /public/index.php!), change the $app variable's declaration to this:$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
To be clear, in an unmodified installation, the lines to be replaced with the above snippet are here:https://github.com/laravel/laravel/blob/master/bootstrap/app.php#L14-L16
2.) Create the file
/app/Application.php. Populate it with the following contents:<?php namespace App;
class Application extends \Illuminate\Foundation\Application
{
public function publicPath()
{
return $this->basePath . '/../../web';
}
}
Be sure to change the return value in the above method to reflect the actual path to the desired public directory on your system.
That's all there is to it! Happy to answer any questions if you're still stuck.