Is there a helper method for getting the absolute path to storage directory of masonite?

55 Views Asked by At

I need to be able to get the absolute path in my controller and my views for a storage path. Some storage paths are different for different static assets in my Masonite application.

How can I do this?

1

There are 1 best solutions below

0
Joseph Mancuso On

Masonite has a helper for this. You can use it directly in your views like this:

Assuming a configuration like this:

DRIVERS = {
    'disk: {
        'location': '/storage/directory'
    }
}

You can do this:

<img src="{{ static('disk', 'profile.jpg')">

this will result in an output like /storage/directory/profile.jpg

Now assuming you had a configuration file like this:

DRIVERS = {
    'disk: {
        'location': {
            'storage': '/storage/directory',
            'uploads': '/storage/uploads',
        }
    }
}

You can just slightly modify your static helper:

<img src="{{ static('disk.uploads', 'profile.jpg')">

You can also use the helper outside of views by using from masonite.helpers import static