Laravel ships with the default public folder for all the public accessible files/assets/images however if you are like me sometimes in a company setting you just need to use public_html or htdocs in instead of the public folder.

So lets tackle that right here!

Extending the Laravel Application

Well extending the application class of Laravel is extremely easy and it allows us to set folder paths custom settings and loads more!

So let’s get started! First create let us take a look at bootstrap/app.html?php namespace Acme; use Illuminate\Foundation\Application; class AcmeApplication extends Application { }

Now to load the framework based on our class lets change the default class loader in bootstrap/app.html?php $app = new Acme\AcmeApplication( realpath(__DIR__.’/../‘) );

Now your application is running thru your own custom Application Class.

So John, thats nice but what’s next?

Well lets start by taking a look at all the things we can extend that might be handy to know.

public function version()  
public function setBasePath()  
public function path()  
public function basePath()  
public function configPath()  
public function databasePath()  
public function langPath()  
public function publicPath()  
public function storagePath()  
public function loadEnvironmentFrom($file)  
public function environmentFile()  
public function environment()  
public function isLocal()  
public function getCachedConfigPath()  
public function getCachedRoutesPath()  
public function isDownForMaintenance()  
public function getLocale()  

And off course there are a lot more classes in there but for us we will focus on the paths.

First let us start using a public_html folder instead of the public directory. In Acme\AcmeApplication lets overwrite the publicPath() function with our own

public function publicPath()  
    return $this->basePath . ‘/public_html’;


and you’re done! now when you point your virtual host to publichtml all the application functions like publicpath() will know where to look for the public folder!

Just for fun!

I always *(actually never)* want to use a different storage dir I just don’t like the name **storage** i want to use **stash**. Well this pretty darn easy just overwrite the default one like:
class AcmeApplication extends Application  
    public function publicPath()
        return $this->basePath . ‘/public_html’;

    public function storagePath()
        return $this->basePath . ‘/stash’;

Bam and you are done! everything will store/remove and updates from the stash folder.

Well i think you get the point.

Have fun extending the crap out of the Application class!

© 2015. All Rights Reserve John in 't Hout.