How To Get Path From Laravel 8 Application Root

Reading Time: 3 minutes
6,340 Views

Inside this article we will see the classified information to get path from laravel 8 application. There are several helper functions of laravel which helps get the path of public directory, app directory, storage directory and also base directory.

If you are looking for an article which gives you the understanding of laravel 8 helper functions to get paths then you are at the right place to learn.

There are several Laravel 8 helper functions to get path of working directory, we will also see the basic differences between those functions.

Learn More –

Let’s get started.


Laravel Installation

We will create laravel project using composer. So, please make sure your system should have composer installed. If not, may be this article will help you to Install composer in system.

Here is the command to create a laravel project-

composer create-project --prefer-dist laravel/laravel blog

To start the development server of Laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.


Laravel 8 – Get Path Helper Functions

Laravel provides these following functions which helps to get application directory path, storage directory, app directory, etc.

  • base_path()
  • app_path()
  • storage_path()
  • public_path()

base_path()

It will return your application path means project folder path.

base_path(); // Path of application root

Example

Route::get('/', function () {
    return base_path();
});

app_path()

It will return your /app directory path.

app_path(); // Path of /app folder

Example

Route::get('/', function () {
    return app_path();
});

storage_path()

It will return your /storage directory path.

storage_path(); // Path of /storage folder

Example

Route::get('/', function () {
    return storage_path();
});

public_path()

It will return your /public directory path.

public_path(); // Path of /public folder

Example

Route::get('/', function () {
    return public_path();
});

We hope this article helped you to learn How To Get Path From Laravel 8 Application Root in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.