Spread the love

In this blog post, we’ve shown you how to get the path to your Laravel application root path directory. If you need to get the path from anywhere in your application, you can use the Laravel public_path() helper function. If you need to get the path to your application’s storage directory, you can use the storage_path() helper function. These are just a few of the ways you can get the path to your Laravel application’s root directory.

Laravel has helpers to get the path of root folder, public folder, assets folder, storage folder, app folder.

To get the path of root application folder we can use base_path() function in laravel which gives the path of root folder in laravel project.

base_path();
//we can pass parameters to base_path function

base_path("app/Http/Controllers");

Output will be:

var/www/html/app/Http/Controllers

To get the path of storage folder in laravel we can user storage_path() function which gives path of storage folder.

storage_path();
//we can pass parameters to storage_path() function

storage_path("app");

Output will be:

var/www/html/storage/app

To get the path of app folder in laravel we can user app_path() function which gives path of app folder.

app_path();
//we can pass parameters to base_path() function

app_path("controllers");

Output will be:

var/www/html/app/controllers

To get the path of public folder in laravel we can user public_path() function which gives path of public folder.

public_path();
//we can pass parameters to public_path() function

public_path("images");

Output will be:

var/www/html/public/images

Read more about the helpers to get the access of directories in How to get folder paths using helpers in laravel?

Leave a Reply